[jboss-user] [EJB 3.0] - compounded primary key with ejb 3.0
jfheintz
do-not-reply at jboss.com
Mon Aug 20 10:42:36 EDT 2007
Hello,
it is now three week I tried to migrate from ejb 2.0 to ejb 3.0, I finally make it work, but when I have a look to the DB,
hibernate as change my table which have a compounded primary key!!!!
Here is an example:
--- TABLE: SI_SITE ---
CREATE TABLE SI_SITE (
siteId BIGSERIAL,
name VARCHAR(128)
);
--- TABLE: SI_TIMEUNIT ---
CREATE TABLE SI_TIMEUNIT (
timeUnitId BIGSERIAL,
fromDate TIMESTAMP,
toDate TIMESTAMP
);
--- TABLE: SI_BROWSERDESC ---
CREATE TABLE SI_BROWSERDESC (
browserDescId VARCHAR(128),
name VARCHAR(128)
);
--- TABLE: SI_BROWSERSTAT ---
CREATE TABLE SI_BROWSERSTAT (
timeUnit_timeUnitId BIGINT,
site_siteId BIGINT,
browserDesc_browserDescId VARCHAR(128),
view INTEGER,
);
ALTER TABLE SI_BROWSERSTAT ADD PRIMARY KEY (timeUnit_timeUnitId, site_siteId, browserDesc_browserDescId);
ALTER TABLE SI_BROWSERSTAT ADD CONSTRAINT SI_BROWSERSTAT_timeUnit_HAS_SI_TIMEUNIT FOREIGN KEY ( timeUnit_timeUnitId ) REFERENCES SI_TIMEUNIT( timeUnitId );
ALTER TABLE SI_BROWSERSTAT ADD CONSTRAINT SI_BROWSERSTAT_site_HAS_SI_SITE FOREIGN KEY ( site_siteId ) REFERENCES SI_SITE( siteId );
ALTER TABLE SI_BROWSERSTAT ADD CONSTRAINT SI_BROWSERSTAT_browserDesc_HAS_SI_BROWSERDESC FOREIGN KEY ( browserDesc_browserDescId ) REFERENCES SI_BROWSERDESC( browserDescId );
---------------- BrowserStatEJB3 ---------------------------
@Entity
@IdClass(BrowserStatPK.class)
@Table(name="SI_BROWSERSTAT")
public class BrowserStatEJB3 {
@EmbeddedId
private BrowserStatPK pk;
@Column(name="view")
private int view;
@javax.persistence.Column(name="timeUnit_timeUnitId", nullable=false, updatable=false, insertable=false)
private java.lang.Long timeUnitTimeUnitId;
@javax.persistence.ManyToOne(fetch = javax.persistence.FetchType.LAZY)
@javax.persistence.JoinColumn(name="timeUnit_timeUnitId")
private data.timeUnit.TimeUnitEJB3 timeUnit=new com.statinfo.stat.data.timeUnit.TimeUnitEJB3();
@javax.persistence.Column(name="site_siteId", nullable=false, updatable=false, insertable=false)
private java.lang.Long siteSiteId;
@javax.persistence.ManyToOne(fetch = javax.persistence.FetchType.LAZY)
@javax.persistence.JoinColumn(name="site_siteId")
private data.site.SiteEJB3 site=new com.statinfo.stat.data.site.SiteEJB3();
@javax.persistence.Column(name="browserDesc_browserDescId", nullable=false, updatable=false, insertable=false)
private java.lang.String browserDescBrowserDescId;
@javax.persistence.ManyToOne(fetch = javax.persistence.FetchType.LAZY)
@javax.persistence.JoinColumn(name="browserDesc_browserDescId")
private data.parameter.browserDesc.BrowserDescEJB3 browserDesc=new com.statinfo.stat.data.parameter.browserDesc.BrowserDescEJB3();
public BrowserStatEJB3() {
}
public BrowserStatPK getPk() {
return this.pk;
}
public void setPk(BrowserStatPK pk) {
this.pk=pk;
}
... other getter and setter ...
---------------- BrowserStatPK ---------------------------
public class BrowserStatPK implements java.io.Serializable {
final static long serialVersionUID = 1L;
private transient int _hashCode = 0;
public java.lang.Long timeUnitTimeUnitId;
public java.lang.Long siteSiteId;
public java.lang.String browserDescBrowserDescId;
public BrowserStatPK() {
}
public BrowserStatPK( java.lang.Long timeUnitTimeUnitId, java.lang.Long siteSiteId, java.lang.String browserDescBrowserDescId) {
this.setTimeUnitTimeUnitId(timeUnitTimeUnitId);
this.setSiteSiteId(siteSiteId);
this.setBrowserDescBrowserDescId(browserDescBrowserDescId);
}
... other getter and setter ...
Now Jboss has added, the following column to my SI_BROWSERSTAT table:
timeUnitTimeUnitId BIGINT,
siteSiteId BIGINT,
browserDescBrowserDescId VARCHAR(128),
pk BYTEARRAY
Why does it not use the good pk column?????
Regards,
JF
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4075876#4075876
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4075876
More information about the jboss-user
mailing list