• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 353
  • Last Modified:

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
0
royjayd
Asked:
royjayd
  • 4
  • 3
1 Solution
 
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
 
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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
 
objectsCommented:
list-index is an index into your list, not the database
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now