Details
-
Bug
-
Resolution: Done
-
Major
-
Preview 4
-
None
-
None
Description
I have two classes with 1:n relationship, Account and AccountName,
and AccountNamePK composite pk class.
I tried to create persistence object Account with one AccountName.
Account has ID as a pk field.
AccountNamePK is composed from id and locale in where id refers to Account id.
During creation JBoss executes select to AccountName table and
puts 'pk' as field into the select.
-----------------------
From JBOSS log:
11:33:59,173 INFO [STDOUT] Hibernate: select accountnam_.accountId, accountnam_.locale, accountnam_.name as name15_, accountnam_.explanation as explanat4_15_,
accountnam_.pk as pk15_, <========= PK field as a column name !!!
accountnam_.id
as id15_ from accountname accountnam_ where accountnam_.accountId=? and accountnam_.locale=?
-----------------------
Account class:
@Entity @SecurityDomain("other") @Table(name = "account")
public class Account implements Serializable, AccountLocal {
private long id;
private Collection<AccountName> names = new ArrayList<AccountName>();
@Id(generate = GeneratorType.IDENTITY) public long getId()
{ return id; }public void setId(long id)
{ this.id = id; } @OneToMany(mappedBy="account", cascade = CascadeType.ALL)
@JoinColumn(name = "accountId", referencedColumnName="id") public Collection<AccountName> getNames()
public void setNames(Collection<AccountName> names)
{ this.names = names; } ...
}
-----------------------
AccountName class:
@Entity @SecurityDomain("other") @Table(name = "accountname")
public class AccountName implements Serializable, AccountNameLocal {
private AccountNamePK pk;
private Account account;
@EmbeddedId(
{ @AttributeOverride(name = "accountId"), @AttributeOverride(name = "locale") })
public AccountNamePK getPk()
public void setPk(AccountNamePK pk)
{ this.pk = pk; }@Transient public long getAccountId()
{ return getPk().getAccountId(); }@Transient public String getLocale()
{ return this.getPk().getLocale(); } @ManyToOne
@JoinColumn(name = "id")
public Account getAccount()
public void setAccount(Account account)
{ this.account = account; } ...
}
------------------
AccountNamePK class:
@Embeddable public class AccountNamePK implements Serializable {
private long accountId;
private String locale;
...
}