I'm having a problem with hibernate creating an integer id column for what is actually an embedded id. The Hibernate libs in use are:
<version.hibernate>3.3.1.GA</version.hibernate>
<version.hibernate-commons-annotations>3.3.0.ga</version.hibernate-commons-annotations>
<version.hibernate-annotations>3.4.0.GA</version.hibernate-annotations>
<version.hibernate-validator>3.1.0.GA</version.hibernate-validator>
<version.hibernate-entitymanager>3.4.0.GA</version.hibernate-entitymanager>
<version.hibernate-entityversioning>1.2.2.GA-hibernate-3.3</version.hibernate-entityversioning>
<version.hibernate-search>3.1.0.GA</version.hibernate-search>
There is an extensive class hierarchy in play which may be part of the problem, but I cannot figure out how.
Code:
@MappedSuperclass
public abstract class Domain<ID extends Serializable> {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="id",insertable=true,nullable=false,unique=true,updatable=false)
private ID id;
@MappedSuperclass
public abstract class BaseEntity<ID extends Serializable> extends Domain<ID> {
// contains fields for create/update who/when, and version
@MappedSuperclass
public abstract class InfoTableEntity<ID extends Serializable> extends BaseEntity<ID> implements Serializable {
// contains a single int field "inactive" which is used as a boolean
@Audited
@Entity
@Table(name="sys_user")
public class SysUser extends InfoTableEntity<Integer> implements Serializable {
...
@Audited(targetAuditMode=RelationTargetAuditMode.AUDITED)
@Fetch(FetchMode.SELECT)
@IndexColumn(name="id",nullable=false)
@OneToMany(fetch=FetchType.EAGER,mappedBy="sysUser")
private List<XrefUserGroup> sysGroupMembershipCollection;
All of the above works as expected. The User and Group tables are correct. However, the join table between two is not.
I have:
Code:
@Embeddable
public class XrefUserGroupId implements Serializable {
@Column(name="sys_group_id", unique=true, nullable=false, insertable=true, updatable=false)
private int sysGroupId;
@Column(name="sys_user_id", unique=true, nullable=false, insertable=true, updatable=false)
private int sysUserId;
@MappedSuperclass
public abstract class BaseEntityCK implements Serializable {
// save as the one above, but without the <ID extends Serializable> extends Domain<ID>
@Audited
@Entity
@Table(name="xref_user_group")
public class XrefUserGroup extends BaseEntityCK implements Serializable {
@EmbeddedId
private XrefUserGroupId id;
//bi-directional many-to-one association to SysUser
@Audited(targetAuditMode=RelationTargetAuditMode.AUDITED)
@ForeignKey(name="fk_xug_su_userid")
@JoinColumn(name="sys_user_id", nullable=false, insertable=false, updatable=false)
@ManyToOne(fetch=FetchType.EAGER,optional=false)
private SysUser sysUser;
and what I end up with is:
Code:
CREATE TABLE xref_user_group (
sys_group_id INT NOT NULL,
sys_user_id INT NOT NULL,
cr_when DATE NOT NULL,
cr_who VARCHAR(20) NOT NULL,
master_key VARCHAR(60),
record_version INT NOT NULL,
up_when DATE NOT NULL,
up_who VARCHAR(20) NOT NULL,
effective_date DATE,
inactive INT NOT NULL,
id INT,
PRIMARY KEY (sys_group_id, sys_user_id),
CONSTRAINT fk_xug_gu_groupid FOREIGN KEY (sys_group_id) REFERENCES sys_group (id) ,
CONSTRAINT fk_xug_su_userid FOREIGN KEY (sys_user_id) REFERENCES sys_user (id),
CONSTRAINT sys_group_id UNIQUE (sys_group_id),
CONSTRAINT sys_user_id UNIQUE (sys_user_id),
INDEX fk_xug_gu_groupid (sys_group_id),
INDEX fk_xug_su_userid (sys_user_id)
)
the "id INT" column is not necessary and the constraints:
Code:
CONSTRAINT sys_group_id UNIQUE (sys_group_id),
CONSTRAINT sys_user_id UNIQUE (sys_user_id),
are very wrong.
Can any one point me in a direction? Thanks!