We help IT Professionals succeed at work.

hibernate <list>

royjayd
royjayd asked
on
Medium Priority
440 Views
Last Modified: 2012-05-11
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
Comment
Watch Question

Author

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

Anyone who can answer my question will be greatly appreciated.
Thanks.
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
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.

Author

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.

Author

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.
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
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

Author

Commented:
List index in a database? Can you explain a little more?
Thx
Java Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.