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
royjaydAsked:
Who is Participating?
 
objectsCommented:
list-index is an index into your list, not the database
0
 
royjaydAuthor Commented:
whats that link?It has got nothing to do with my question.

Anyone who can answer my question will be greatly appreciated.
Thanks.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
objectsCommented:
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.
0
 
royjaydAuthor Commented:
>>>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.
0
 
royjaydAuthor Commented:
<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.
0
 
objectsCommented:
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
0
 
royjaydAuthor Commented:
List index in a database? Can you explain a little more?
Thx
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.