-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: How to use in idbag
PostPosted: Wed Dec 13, 2006 5:34 pm 
Beginner
Beginner

Joined: Thu Nov 02, 2006 2:23 pm
Posts: 33
Hey,

i use in hyperjaxb2 , it generate a jaxb and hiebenate mapping from xsd.

it supports for collection only in :
Bag,Idbag,List

i have many to many relation (no need for biderctional)

lets say :
Book:
bookId- assign by application (pk)
name

Company:
companyId -assign by application (pk)
name.

I have a table Book_To_Comany with column:
bookId
companyId

i want that book will have many to many relation with company.

how can i write the idbag section in Book hbm?

I dont need list , because the order is not important and i dont need or want index, and bag is not good due to performence ( and Book can not have multiple company)

Thank you


Top
 Profile  
 
 Post subject: bag
PostPosted: Wed Dec 13, 2006 6:19 pm 
Newbie

Joined: Wed Dec 06, 2006 6:30 pm
Posts: 8
The idbag mapping should be something like:
Code:
<idbag name="companies" table="company" lazy="true">
  <collection-id type="long" column="id">
    <generator class="native"/>
  </collection-id>
  <key column="book_id"/>
  <many-to-many class="Company" column="company_id"/>
</idbag>


Consult the following manual page for more information: http://www.hibernate.org/hib_docs/v3/reference/en/html/collections.html#collections-idbag

-David


Top
 Profile  
 
 Post subject: Thank you , can you please explain what is the collection-id
PostPosted: Wed Dec 13, 2006 6:34 pm 
Beginner
Beginner

Joined: Thu Nov 02, 2006 2:23 pm
Posts: 33
for wich column it need to be mapped?
why you need generator?

i did something like this but i got ClassCastException with the long


Code:
Caused by: java.lang.ClassCastException
   at org.hibernate.type.LongType.set(LongType.java:42)
   at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:83)
   at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:65)
   at org.hibernate.persister.collection.AbstractCollectionPersister.writeIdentifier(AbstractCollectionPersister.java:784)
   at org.hibernate.persister.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:1074)
   at org.hibernate.action.CollectionRecreateAction.execute(CollectionRecreateAction.java:26)
   at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:143)
   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:993)
   at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:340)
   at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
   at com.mercado.s2002.analysis.util.TransactionManager.commit(TransactionManager.java:230)
   at com.mercado.s2002.analysis.util.TransactionManager.close(TransactionManager.java:370)
   at com.mercado.s2002.analysis.dao.hibernate.QueryEventDAO.save(QueryEventDAO.java:54)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 13, 2006 6:40 pm 
Newbie

Joined: Wed Dec 06, 2006 6:30 pm
Posts: 8
You would need a generator for the primary key for each item--unless you would be assigning them by hand.

Sorry, the table in <idbag ...> should be whatever the association table is and NOT company table. Also, make sure that table has the id column.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.