-
1. Re: Duplicate Column Error
epbernard Jul 1, 2005 7:14 AM (in response to keeyes)I don't get you, pealse show a simple code describing your needs.
-
2. Re: Duplicate Column Error
keeyes Jul 3, 2005 9:03 PM (in response to keeyes)Here it goes
@Entity
@Table(name = "CPAY")
@NamedQuery(name="Cpay.findByPrimaryKey",queryString="SELECT OBJECT(c) FROM Cpay c WHERE c.cpayId =: cpayId")
@NamedQueries({
@NamedQuery(name = "Cpay.findByAccId",queryString="SELECT OBJECT(c) FROM Cpay c WHERE c.accountId =: accountId")
}
)
public class Cpay implements java.io.Serializable
{
private java.lang.Long cpayId ;
private Account account;
@Id(generate = GeneratorType.AUTO)
@Column(name="CPAY_ID")
public Long getCpayId()
{
return cpayId ;
}
public void setCpayId(java.lang.Long cpayId)
{
this.cpayId = cpayId;
}
/* This creates a column by name account_id in Cpay table */
@ManyToOne
@JoinColumn(name = "account_id")
public Account getAccount()
{
return account;
}
public void setAccount(Account account)
{
this.account = account;
}
If I don't put setter and getter for account_id, then the Named Query c.accountId =: accountId won't work since there is no getter for
accountId.
But the same time, If I put a getter and setter for accountId, while deployment it complains for a duplicate column by name account_id
since the relationship itself creates a column account_id with referential integrity
Regards -
3. Re: Duplicate Column Error
epbernard Jul 4, 2005 10:30 AM (in response to keeyes)where c.account.accountId = :accountId
or even better
where c.account = :account -
4. Re: Duplicate Column Error
elkner Jul 4, 2005 6:15 PM (in response to keeyes)"epbernard" wrote:
or even better
where c.account = :account
Can you give a hint, why this is better? Just for OO-POV or perf ? -
5. Re: Duplicate Column Error
epbernard Jul 11, 2005 1:16 PM (in response to keeyes)it is better from an abstraction POV, not significantly slower if any
-
6. Re: Duplicate Column Error
elkner Jul 11, 2005 2:45 PM (in response to keeyes)Ahh, ok. Asking because I think, performance is important and thus passing an id around (i.e. from the client to the server) might give one better performance/less network traffic, than passing the complete object (account) around...