EJB3 Table Creation
edstorm Jun 6, 2005 2:13 PMHi,
I am currently working with the ejb3 implementation in jboss-head and have run into some trouble with automatic table creation for entities that inherit a one to many relationship via TABLE_PER_CLASS Inheritance. Specifically, If EntityB inherits a One-To-Many realtionship to EntityC from EntityA then the generated Table Create statement for EntityB will contain two fk columns ( with the same name ).
I should mention that if I create the tables manually everything works as I expect. Below are code snippets that can be used to reproduce the behavior. I am not 100% complete with my reading of the ejb3 draft spec so if this use case is not allowed by the spec I apologize for the wasted space.
Using the code below, the TABLE Create statement that is generated for EasyActivityEvent is:
create table TEST_EA ( id int4 not null, easyDay_fk int4, easyDay_fk int4, primary key (id) )
EntityA
@Entity @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) @Table( name = "TEST_EE" ) public abstract class EasyEvent implements java.io.Serializable { private int mId; private EasyDay mEasyDay; @Id(generate = GeneratorType.AUTO) public int getId() { return mId; } public void setId( int pId ) { mId = pId; } @ManyToOne @JoinColumn( name = "easyDay_fk" ) public EasyDay getEasyDay() { return mEasyDay; } public void setEasyDay( EasyDay pEasyDay ) { this.mEasyDay = pEasyDay; } }
EntityB
@Entity @Table(name = "TEST_EA") public class EasyActivityEvent extends EasyEvent { }
EntityC
@Entity @Table(name = "TEST_ED") @NamedQuery( name = "easyDay.findAll", queryString = "Select Distinct Object(p) FROM EasyDay p") public class EasyDay implements java.io.Serializable { private int mId; Set<EasyActivityEvent> mEasyActivityEvents; @Id(generate = GeneratorType.AUTO) public int getId() { return mId; } public void setId( int pId ) { mId = pId; } @OneToMany(mappedBy="easyDay", cascade=CascadeType.ALL, fetch=FetchType.EAGER) public Set<EasyActivityEvent> getEasyActivityEvents( ) { return mEasyActivityEvents; } public void setEasyActivityEvents( Set<EasyActivityEvent> pEasyActivityEvents ) { this.mEasyActivityEvents = pEasyActivityEvents; } }