Jay Roy
asked on
hibernate <list>
hi guys
I have a hibernate question and i need some clarification
I have two tables PROJECT and PROJECT_USERS . A Project has multiple users so i am using one-to-many relationship in my hbm.xml file below
<class name="hibernate.entity.Pro ject" table="PROJECT" catalog="eProject">
<list name="projectUserses" table="PROJECT_USERS" inverse="true" lazy="false" fetch="select">
<key column="PROJECT_ID" not-null="true" />
<list-index column="USER_ID" />
<one-to-many class="hibernate.entity.Pr ojectUsers " />
</list>
</class>
My table structure is
PROJECT table
PROJECT_ID (PK)
Name
PROJECT_USERS table
PROJECT_ID (PK)
USER_ID (PK)
Role
Users table
USER_ID (PK)
Fname
Lname
So based on the scenario above is my <list> definition above correct? specifically are these two lines correct ?
<key column="PROJECT_ID" not-null="true" /> --> Is this column PROJECT_ID the primary key column of PROJECT table?
<list-index column="USER_ID" /> Is this column USER_ID the primary key column for PROJECT_USERS table?
Am i moving correctly?
Any help appreciated
thanks
I have a hibernate question and i need some clarification
I have two tables PROJECT and PROJECT_USERS . A Project has multiple users so i am using one-to-many relationship in my hbm.xml file below
<class name="hibernate.entity.Pro
<list name="projectUserses" table="PROJECT_USERS" inverse="true" lazy="false" fetch="select">
<key column="PROJECT_ID" not-null="true" />
<list-index column="USER_ID" />
<one-to-many class="hibernate.entity.Pr
</list>
</class>
My table structure is
PROJECT table
PROJECT_ID (PK)
Name
PROJECT_USERS table
PROJECT_ID (PK)
USER_ID (PK)
Role
Users table
USER_ID (PK)
Fname
Lname
So based on the scenario above is my <list> definition above correct? specifically are these two lines correct ?
<key column="PROJECT_ID" not-null="true" /> --> Is this column PROJECT_ID the primary key column of PROJECT table?
<list-index column="USER_ID" /> Is this column USER_ID the primary key column for PROJECT_USERS table?
Am i moving correctly?
Any help appreciated
thanks
http://www.vaannila.com/hibernate/hibernate-example/hibernate-mapping-many-to-many-1.html
ASKER
whats that link?It has got nothing to do with my question.
Anyone who can answer my question will be greatly appreciated.
Thanks.
Anyone who can answer my question will be greatly appreciated.
Thanks.
thats actually a many to many.
Did you specifically want a List?
And did you need the role property? You'll need an extra entity if you do.
Did you specifically want a List?
And did you need the role property? You'll need an extra entity if you do.
ASKER
>>>Did you specifically want a List?
Yes
>>And did you need the role property? You'll need an extra entity if you do
yeah, i have three entities
Project.java/ project.hbm.xml
Users.java/user.hbm.xml
ProjectUsers/projectUser.h bm.xml
But the list which i defined above
<list name="projectUserses" table="PROJECT_USERS" inverse="true" lazy="false" fetch="select">
<key column="PROJECT_ID" not-null="true" />
<list-index column="USER_ID" />
<one-to-many class="hibernate.entity.Pr ojectUsers " />
</list>
is throwing error
i am searching by projectId 227565 (corresponding to hibernate.entity.Project)
and getting this error on the list definition
[4/21/11 15:32:13:463 EDT] 00000017 SystemErr R org.hibernate.exception.Da taExceptio n: could not initialize a collection: [hibernate.entity.Project. projectUse rses#22756 5]
at org.hibernate.exception.SQ LStateConv erter.conv ert(SQLSta teConverte r.java:100 )
at org.hibernate.exception.JD BCExceptio nHelper.co nvert(JDBC ExceptionH elper.java :66)
...
....
Caused by: java.sql.SQLException: The value supplied cannot be converted to INTEGER. at net.sourceforge.jtds.jdbc. Support.co nvert(Supp ort.java:6 53)
at net.sourceforge.jtds.jdbc. JtdsResult Set.getInt (JtdsResul tSet.java: 641)
at net.sourceforge.jtds.jdbc. JtdsResult Set.getInt (JtdsResul tSet.java: 968)
thanks for response and any help appreciated.
Yes
>>And did you need the role property? You'll need an extra entity if you do
yeah, i have three entities
Project.java/ project.hbm.xml
Users.java/user.hbm.xml
ProjectUsers/projectUser.h
But the list which i defined above
<list name="projectUserses" table="PROJECT_USERS" inverse="true" lazy="false" fetch="select">
<key column="PROJECT_ID" not-null="true" />
<list-index column="USER_ID" />
<one-to-many class="hibernate.entity.Pr
</list>
is throwing error
i am searching by projectId 227565 (corresponding to hibernate.entity.Project)
and getting this error on the list definition
[4/21/11 15:32:13:463 EDT] 00000017 SystemErr R org.hibernate.exception.Da
at org.hibernate.exception.SQ
at org.hibernate.exception.JD
...
....
Caused by: java.sql.SQLException: The value supplied cannot be converted to INTEGER. at net.sourceforge.jtds.jdbc.
at net.sourceforge.jtds.jdbc.
at net.sourceforge.jtds.jdbc.
thanks for response and any help appreciated.
ASKER
<list name="projectUserses" table="PROJECT_USERS" inverse="true" lazy="false" fetch="select">
<key column="PROJECT_ID" not-null="true" />
<list-index column="USER_ID" />
<one-to-many class="hibernate.entity.Pr ojectUsers " />
</list>
when i replace the above list with set, it works fine. so i am really thinking
<list-index column="USER_ID" /> is the suspect.
<key column="PROJECT_ID" not-null="true" />
<list-index column="USER_ID" />
<one-to-many class="hibernate.entity.Pr
</list>
when i replace the above list with set, it works fine. so i am really thinking
<list-index column="USER_ID" /> is the suspect.
well it doesn't really make sense to use an is as a list index, you don't actually have a list index in the database
ASKER
List index in a database? Can you explain a little more?
Thx
Thx
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.