Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Object Relational Mapping
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Object Relational Mapping
exception on hibernate
Alan Hermin
Ranch Hand
Posts: 290
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
hi all,
This is the first
test
on hibernate, so i use
This Link
, my Database is mySQL, but i got this exception:
Exception in thread "main" org.hibernate.HibernateException: No TransactionManagerLookup specified at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:503) at de.laliluna.example.TestExample.createHoney(TestExample.java:69) at de.laliluna.example.TestExample.main(TestExample.java:23)
Lakshmi Dasari
Ranch Hand
Posts: 35
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Assuming that your settings are just the way outlined in the article,
try removing this property
<property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
and also ensure you have this property
<property name="current_session_context_class">thread</property>
Lakshmi
Alan Hermin
Ranch Hand
Posts: 290
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hhi Lakshmi Dasari,
but sorry ,it did NOT work, and i get the same exception..
Lakshmi Dasari
Ranch Hand
Posts: 35
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Can you post the contents of your hibernate.cfg.xml. You would have got this exception if the session context was "jta" instead of "thread"
Lakshmi
Alan Hermin
Ranch Hand
Posts: 290
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
ok, this is my hibernate.cfg.xml file:
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="connection.url"> jdbc:mysql://localhost/mysql </property> <property name="connection.username">root</property> <property name="connection.driver_class"> com.mysql.jdbc.Driver </property> <property name="dialect"> org.hibernate.dialect.MySQLDialect </property> <property name="connection.password">alaa</property> <property name="transaction.factory_class"> org.hibernate.transaction.JDBCTransactionFactory </property> <!-- thread is the short name for org.hibernate.context.ThreadLocalSessionContext and let Hibernate bind the session automatically to the thread --> <property name="current_session_context_class">thread</property> <!-- this will show us all sql statements --> <property name="hibernate.show_sql">true</property> <!-- mapping files --> <mapping resource="de/laliluna/example/Honey.hbm.xml" /> </session-factory> </hibernate-configuration>
and this is Honey.hbm.xml file :
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" > <hibernate-mapping> <class name="de.laliluna.example.Honey" table="honey"> <id name="id" column="id" type="java.lang.Integer"> <generator class="increment" /> </id> <property name="name" column="name" type="java.lang.String" /> <property name="taste" column="taste" type="java.lang.String" /> </class> </hibernate-mapping>
and this is the TestExample.java file ,
package de.laliluna.example; import java.util.Iterator; import java.util.List; import org.apache.log4j.Logger; import org.hibernate.HibernateException; import org.hibernate.Session; import org.hibernate.Transaction; import org.hibernate.dialect.MySQLDialect; import de.laliluna.hibernate.InitSessionFactory; public class TestExample { private static Logger log = Logger.getLogger(TestExample.class); public static void main(String[] args) { Honey forestHoney = new Honey(); forestHoney.setName("forest honey"); forestHoney.setTaste("very sweet"); Honey countryHoney = new Honey(); countryHoney.setName("country honey"); countryHoney.setTaste("tasty"); createHoney(forestHoney); createHoney(countryHoney); log.debug(forestHoney); log.debug(countryHoney); listHoney(); //deleteHoney(forestHoney); listHoney(); } private static void listHoney() { Transaction tx = null; Session session = InitSessionFactory.getInstance().getCurrentSession(); try { tx = session.beginTransaction(); List honeys = session.createQuery("select mysql.h from Honey as h").list(); for (Iterator iter = honeys.iterator(); iter.hasNext() :wink: { Honey element = (Honey) iter.next(); log.debug(element); } tx.commit(); } catch (HibernateException e) { e.printStackTrace(); if (tx != null && tx.isActive()) tx.rollback(); } } private static void deleteHoney(Honey honey) { Transaction tx = null; Session session = InitSessionFactory.getInstance().getCurrentSession(); try { tx = session.beginTransaction(); session.delete(honey); tx.commit(); } catch (HibernateException e) { e.printStackTrace(); if (tx != null && tx.isActive()) tx.rollback(); } } private static void createHoney(Honey honey) { Transaction tx = null; Session session = InitSessionFactory.getInstance().getCurrentSession(); try { tx = session.beginTransaction(); session.save(honey); tx.commit(); } catch (HibernateException e) { e.printStackTrace(); if (tx != null && tx.isActive()) tx.rollback(); } } }
the remaining files remaining as the same as they are in the URL provided
Regards
With a little knowledge, a
cast iron skillet
is non-stick and lasts a lifetime.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
StaleObjectStateException: can catch exception but stack trace still prints
Make hibernate use JTA transaction in WAS 5.1
Problem with Hibernate test application
NullPointerException in creating Session Object using Hibernate
hibernate.cfg.xml location for Eclipse project
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
More...