Link to home
Start Free TrialLog in
Avatar of Jay Roy
Jay RoyFlag for United States of America

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.Project" 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.ProjectUsers" />
  </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
Avatar of sweetfa2
sweetfa2
Flag of Australia image

Avatar of Jay Roy

ASKER

whats that link?It has got nothing to do with my question.

Anyone who can answer my question will be greatly appreciated.
Thanks.
Avatar of Mick Barry
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.
Avatar of Jay Roy

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.hbm.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.ProjectUsers" />
 </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.DataException: could not initialize a collection: [hibernate.entity.Project.projectUserses#227565]      
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:100)
      at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
...
....
Caused by: java.sql.SQLException: The value supplied cannot be converted to INTEGER.      at net.sourceforge.jtds.jdbc.Support.convert(Support.java:653)
      at net.sourceforge.jtds.jdbc.JtdsResultSet.getInt(JtdsResultSet.java:641)
      at net.sourceforge.jtds.jdbc.JtdsResultSet.getInt(JtdsResultSet.java:968)


thanks for response and any help appreciated.
Avatar of Jay Roy

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.ProjectUsers" />
 </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
Avatar of Jay Roy

ASKER

List index in a database? Can you explain a little more?
Thx
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial