-->
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.  [ 9 posts ] 
Author Message
 Post subject: Insertion problem in many-to-many object
PostPosted: Sun Jan 04, 2004 10:12 am 
Newbie

Joined: Sun Jan 04, 2004 10:05 am
Posts: 4
Location: tehran
Hi all,

I have a many-to-many Object Relation (an appointment that have many invitations) I use xdoclet and struts infront of hibernate.
It seems that everything is ok in my code but after saving new object the information of invitations is not inserted to Link table : this is part of my code

/**
* @hibernate.set
* role="invitations"
* table="tevent_partner"
* cascade="all"
* readonly="true"
* @hibernate.collection-key
* column="eventId"
* @hibernate.collection-many-to-many
* class="org.shabdiz.shabware.entity.partners.PartnerValue"
* column="partnerId"
* @return java.util.Set
*
*/
public Set getInvitations() {
return invitations;
}

public void setInvitations(Set invitations) {
this.invitations = invitations;
}


and action to save the Event:

public String saveMethod(HttpServletRequest request, ActionForm actionForm) throws Exception {
EventValue eventValue = (EventValue) actionForm;
System.out.println("test data:"+eventValue.getInvitations().toArray()[0]);
getFacadeLocal().getEventLocal().addEvent(eventValue);
return SAVE;
}

thank you in advance


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 04, 2004 2:08 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Show the mapping file.
Show the *real* code, the one you show points nowhere.
What version of Hibernate are you using ?
Role is deprecated for a while. Be sure to use latest evrsion of xdoclet.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: XDOCLET and Hibernate 2.1
PostPosted: Mon Jan 05, 2004 2:51 am 
Hi,


Does the most recent version of xdoclet generate Hibernate 2.1 mappings?


Regards,

Eliot


Top
  
 
 Post subject:
PostPosted: Mon Jan 05, 2004 6:33 am 
Newbie

Joined: Sun Jan 04, 2004 10:05 am
Posts: 4
Location: tehran
Hi, and thanx for your attention,

my xdiclet version is 1.2.b3 and hibernate version is 2.0.3

this is my hibernate mapping of basic class Event :

<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class
name="org.shabdiz.shabware.entity.calendar.EventValue"
table="tevent"
dynamic-update="false"
dynamic-insert="false"
>

<id
name="eventId"
column="eventId"
type="java.lang.String"
>
<generator class="uuid.hex">
</generator>
</id>

<property
name="title"
type="string"
update="true"
insert="true"
column="title"
length="50"
/>

<property
name="eventType"
type="string"
update="true"
insert="true"
column="eventType"
length="50"
/>

<property
name="date"
type="java.sql.Date"
update="true"
insert="true"
column="date"
/>

<property
name="isAllday"
type="boolean"
update="true"
insert="true"
column="isAllday"
/>

<property
name="time"
type="java.sql.Time"
update="true"
insert="true"
column="time"
/>

<property
name="duration"
type="java.sql.Time"
update="true"
insert="true"
column="duration"
/>

<property
name="location"
type="java.lang.String"
update="true"
insert="true"
column="location"
length="50"
/>

<property
name="notes"
type="string"
update="true"
insert="true"
column="notes"
length="256"
/>

<property
name="haverepeat"
type="boolean"
update="true"
insert="true"
column="haverepeat"
/>

<property
name="repeatType"
type="int"
update="true"
insert="true"
column="repeatType"
/>

<property
name="repeatPart1"
type="java.lang.String"
update="true"
insert="true"
column="repeatPart1"
length="50"
/>

<property
name="repeatPart2"
type="java.lang.String"
update="true"
insert="true"
column="repeatPart2"
length="50"
/>

<property
name="repeatPart3"
type="java.lang.String"
update="true"
insert="true"
column="repeatPart3"
length="50"
/>

<property
name="until"
type="java.sql.Date"
update="true"
insert="true"
column="until"
/>

<property
name="haveEndDate"
type="boolean"
update="true"
insert="true"
column="haveEndDate"
/>

<property
name="haveReminder"
type="boolean"
update="true"
insert="true"
column="haveReminder"
/>

<property
name="remindFirst"
type="java.lang.String"
update="true"
insert="true"
column="remindFirst"
length="50"
/>

<property
name="remindSecond"
type="java.lang.String"
update="true"
insert="true"
column="remindSecond"
length="50"
/>

<property
name="byWhat"
type="int"
update="true"
insert="true"
column="byWhat"
/>

<property
name="street"
type="java.lang.String"
update="true"
insert="true"
column="street"
length="50"
/>

<many-to-one
name="cityValue"
class="org.shabdiz.shabware.entity.partners.CityValue"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="city_fk"
/>

<one-to-one
name="userValue"
class="org.shabdiz.shabware.entity.partners.UserValue"
cascade="none"
outer-join="auto"
constrained="false"
/>

<property
name="phone"
type="java.lang.String"
update="true"
insert="true"
column="phone"
length="20"
/>

<set
name="invitations"
table="tevent_partner"
lazy="false"
inverse="false"
cascade="all"
sort="unsorted"
>

<key
column="eventId"
/>

<many-to-many
class="org.shabdiz.shabware.entity.partners.PartnerValue"
column="partnerId"
outer-join="auto"
/>

</set>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-EventValue.xml
containing the additional properties and place it in your merge dir.
-->

</class>

</hibernate-mapping>


the problem is in many-to-many part (last piece of code )
I thought that maybe error was in struts that can not transfer data from multiple <select> in form to my value object but even after adding some data after execution of action nothing was added to database .

here is mapping of intermediate class :(EventPartner)

<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class
name="org.shabdiz.shabware.entity.calendar.EventPartnerValue"
table="tevent_partner"
dynamic-update="false"
dynamic-insert="false"
>

<id
name="id"
column="id"
type="java.lang.String"
>
<generator class="uuid.hex">
</generator>
</id>

<property
name="partnerId"
type="java.lang.String"
update="true"
insert="true"
column="partnerId"
length="50"
/>

<property
name="eventId"
type="java.lang.String"
update="true"
insert="true"
column="eventId"
length="50"
/>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-EventPartnerValue.xml
containing the additional properties and place it in your merge dir.
-->

</class>

</hibernate-mapping>


thank you
Ghazaleh


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 05, 2004 2:06 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
You should not map EventPartnerValue, This is a relation table and doesn't need to appear in the object model.

How are data actually inserted in the set ?

Do a try catch to see if an exceptino occurs

Add debug logs of Hibernate to see what happen

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 06, 2004 7:42 am 
Newbie

Joined: Sun Jan 04, 2004 10:05 am
Posts: 4
Location: tehran
Now my hibernate and xdoclet are both upgraded to last versions.
I deleted the EventPartner value Object , you are right there no need to this file.

but steel after executing code there is just this insertion sql , and there is no sql code for insertion to tevent_partner table:

insert into tevent (title, eventType, date, isAllday, time, duration, location, notes, haverepeat, repeatType, repeatPart1, repeatPart2, repeatPart3, until, haveEndDate, haveReminder, remindFirst, remindSecond, byWhat, street, city_fk, phone, eventId) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)

and when i wanted to print information on invitation Set there was nothing on it ?
can you help me about transfering data from jsp form to Set ?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 06, 2004 12:18 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
if inverse, is really "false" on the set, it should work.
Check how the set collection is done in your form.
Try to init it manually.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 07, 2004 8:19 am 
Newbie

Joined: Sun Jan 04, 2004 10:05 am
Posts: 4
Location: tehran
Hi there,

I made all probably mistakes correct, it seems that all of my mapping files are OK.
to avoid problem of transfering data to Set i add some information to "invitations" manually.

but steel nothing was added to intermediate table .
this is my action code :

--------------------------------------------------------------------------------
package org.shabdiz.shabware.session.calendar;

...

/**
*@ejb.bean
* type="Stateless"
* name="Event"
* local-jndi-name="ejb/local/Event"
* view-type="local"
* transaction-type="Bean"
*
* @ejb.util
* generate="physical"
*
*/

public class EventEJB implements SessionBean {
private SessionContext sessionContext;
private static Logger logger = Logger.getLogger(EventEJB.class.getName());
protected SessionFactory sessionFactory;
/****************************************************************************/
/* B U S I N E S S M E T H O D S */
/****************************************************************************/
/**
* @ejb.interface-method
*/
public void addEvent(EventValue eventValue) throws Exception {
if (logger.isDebugEnabled())
logger.debug("Adding Event: " + eventValue);
Session session = sessionFactory.openSession();
Transaction transaction = null;
try {
transaction = session.beginTransaction();
Set invitations= new HashSet();
List list = session.find("from PartnerValue");
Iterator iter = list.iterator();
while(iter.hasNext()){
PartnerValue p = (PartnerValue)iter.next();
System.out.println("PartnerValue is:"+p.toString());
invitations.add(p);
}
eventValue.setInvitations(invitations);
iter = eventValue.getInvitations().iterator();
while(iter.hasNext()){
System.out.println("PartnerValue in object is :"+iter.next().toString());
}
session.save(eventValue);
transaction.commit();
System.out.println("event saved");
} catch (Exception e) {
logger.error("addEvent: " + e);
if (transaction != null)
transaction.rollback();
throw e;
} finally {
session.close();
}
}

/**
* @ejb.interface-method
*/
public List getAllEvents() throws Exception {
if (logger.isDebugEnabled())
logger.debug("Getting All Eventss!");
List list = null;
Session session = sessionFactory.openSession();
try {
list = session.find("from EventValue");
} catch (Exception e) {
logger.error("getAllEvents: " + e);
throw e;
} finally {
session.close();
}
return list;
}

/****************************************************************************/
/**
* @ejb.create-method
*/
public void ejbCreate() {
try {
sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (HibernateException ex) {
logger.error("Exception in creating hibernate session factory" + ex);
}
}

public void ejbActivate() throws EJBException, RemoteException {
}

public void ejbPassivate() throws EJBException, RemoteException {
}

public void ejbRemove() throws EJBException, RemoteException {
}

public void setSessionContext(SessionContext sessionContext) throws EJBException, RemoteException {
this.sessionContext = sessionContext;
}
}
---------------------------------------------------------------------------

and my mapping file after change:


<set
name="invitations"
table="tevent_partner"
lazy="true"
inverse="true"
cascade="all"
sort="unsorted"
>

<key
column="eventId"
/>

<many-to-many
class="org.shabdiz.shabware.entity.partners.PartnerValue"
column="partnerId"
outer-join="auto"
/>

</set>

please help, thanx


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 07, 2004 8:32 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Manual transaction management is not necessary if you use Hibernate in an EJB Context, Hibernate automatically takes part in an CMT Transaction, if you use a JTA managed datasource provided by the container. Try removing the transaction management code and do a session.flush() at the end. In every case, do a session.flush() at the end, it never hurts :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 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.