-->
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.  [ 2 posts ] 
Author Message
 Post subject: Urgent help needed one- to- many mappping
PostPosted: Sat Oct 04, 2003 11:14 pm 
Newbie

Joined: Tue Sep 16, 2003 4:45 pm
Posts: 14
Hi,
I am trying to insert an object with one to many mapping and I am getting the following exception
-------------------------------------------------------------------

java.lang.UnsupportedOperationException: The user must supply a JDBC connection
at net.sf.hibernate.connection.UserSuppliedConnectionProvider.getConnect
ion(UserSuppliedConnectionProvider.java:32)
at net.sf.hibernate.impl.SessionFactoryImpl.openConnection(SessionFactor
yImpl.java:396)
at net.sf.hibernate.id.TableGenerator.generate(TableGenerator.java:81)
at net.sf.hibernate.id.TableHiLoGenerator.generate(TableHiLoGenerator.ja
va:59)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:599)
----------------------------------------------------------------------
I am trying to supply the java.sql.Connection object during runtime using the following code


Configuration cfg=new Configuration();
cfg.addClass(User.class);
cfg.addClass(Purchase.class);
SessionFactory sessionFac=cfg.buildSessionFactory();
Class.forName("org.gjt.mm.mysql.Driver");
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/temp","root","xxxxx");
Session sess=sessionFac.openSession(conn);
Transaction tx=null;
tx=sess.beginTransaction();
sess.save(User);
tx.commit();
sess.close();
---------------------------------------------------------
Following is the mapping of hibernate.properties file

hibernate.dialect net.sf.hibernate.dialect.MySQLDialect
hibernate.connection.driver_class org.gjt.mm.mysql.Driver
#hibernate.connection.driver_class com.mysql.jdbc.Driver
hibernate.connection.url jdbc:mysql://localhost:3306/temp
hibernate.connection.username root
hibernate.connection.password xxxx
hibernate.connection.pool_size 10
------------------------------------------
Following are the mapping of user.hbm.xml and Purchase.hmb.xml
User.hbm.xml
<hibernate-mapping>
<class
name="User"
table="user">
<id
name="userid"
column="userid">
<generator class="native"/>
</id>

<property
name="useremail"
column="useremail"
not-null="true"
unique="true"/>

<bag
name="purchase"
table="purchase"
inverse="true"
lazy="true"
cascade="all">

<key column="userid"/>
<one-to-many class="purchase"/>

</bag>
</class>

</hibernate-mapping>
--------------------------------------------------
Purchase.hbm.xml
<hibernate-mapping>
<class
name="Purchase" table="purchase">

<id
name="purchaseid"
column="purchaseid">
<generator class="native"/>
</id>

<many-to-one
name="user"
column="userid"
not-null="true"/>

</class>
</hibernate-mapping>

---------------------------
Any help would be highly appreciated
Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 05, 2003 12:58 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
I would suggest you look at the examples page and find the toolset example we built at JAOO. This shows different setups and configurations that might help you situation.


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