- This topic has 3 replies, 3 voices, and was last updated 19 years, 2 months ago by
Riyad Kalla.
-
AuthorPosts
-
barrinaMemberHi,
I am using Hibernate 3 within MyEclipse 4.1.1. I am new to hibernate and have question about why the MyEclipse is generating all the columns in my table within a composite-id tag and adding a secondary ‘Id’ POJO. I have read a related thread http://www.myeclipseide.com/PNphpBB2+file-viewtopic-t-11684-highlight-compositeid.html, that comes close, but doesn’t really answer my problem.
Under what circumstances will MyEclipse wrap the tables columns in a composite-id tag? I read previously that it was when the number of columns making the primary key was greater than zero. The table I have entered below as way of an example has 3/5 column that are not null, but no primary key — does MyEclipse infer that as the composite key? What about the remaining two coumns, should they be outside of the compostie-id tag and within the normal POJO rather than the POJOId class.
This all seems a bit of a black art — any clarification would be greatly appreciated.
=====
Table creation script
=====/* ACTION is CREATE Table gl */ CREATE TABLE gl ( facility_id NUMBER(10) NOT NULL, dept_code VARCHAR2(15) NOT NULL, gl_account VARCHAR2(20) NOT NULL, gl_category NUMBER NULL, descr VARCHAR2(50) NULL );
There is no primary key or index defined.
====
Generated *.hbm.xml
====<?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <!-- Mapping file autogenerated by MyEclipse - Hibernate Tools --> <hibernate-mapping> <class name="com.premierinc.informatics.oa.pr.pojo.Gl" table="GL" schema="OAR"> <composite-id name="id" class="com.premierinc.informatics.oa.pr.pojo.GlId"> <key-property name="facilityId" type="java.lang.Long"> <column name="FACILITY_ID" precision="10" scale="0" /> </key-property> <key-property name="deptCode" type="java.lang.String"> <column name="DEPT_CODE" length="15" /> </key-property> <key-property name="glAccount" type="java.lang.String"> <column name="GL_ACCOUNT" length="20" /> </key-property> <key-property name="glCategory" type="java.lang.Long"> <column name="GL_CATEGORY" precision="22" scale="0" /> </key-property> <key-property name="descr" type="java.lang.String"> <column name="DESCR" length="50" /> </key-property> </composite-id> </class> </hibernate-mapping>
And I have a Gl.java and GlId.java — can be posted if required.
Kind regards,
Alan Barrington-Hughes
====
May 11, 2006 at 3:44 pm #251953
Riyad KallaMemberEvery table Hibernate maps has to have a PK. If it doesn’t, Hibernate will make one by using every field in the table. Just give your table a PK and Hibernate will stop going nuts making one for you 😉
May 15, 2006 at 4:26 pm #252053
yxanMemberI found this issue and would like to add to this, it would be nice if the plug could allow you to ignore doing that. I am planning to do this as a Select only so a PK is not of any greater concern to me.
so can you create a Hibernate mapping file with no PK? if you only use Selects or will it still blow up?
May 16, 2006 at 1:42 am #252077
Riyad KallaMemberIt will still blow up, try and remove the ID section from the hbm.xml file, it’s invalid according to the Hibernate spec file. Hibernat needs it.
-
AuthorPosts