-->
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.  [ 8 posts ] 
Author Message
 Post subject: Advise, Please
PostPosted: Fri Jan 09, 2004 2:18 pm 
Newbie

Joined: Mon Dec 01, 2003 7:32 pm
Posts: 7
1. what's the difference between hibernate.properties and hibernate.cfg.xml? I should use one or the other or I can use both? I find that some info appear in both files; but not all. Seem when I do cfg.buildSessionFactory() call, hibernate.properties is used; while when I do cfg.config().buildSessionFactory(), it looks for hibernate.cfg.xml. What's the best practice in using these two files?

2. In my hibernate.properties, I have hibernate.dbcp properies (from samples) defined. However, when I ran, I got the error:
(connection.DBCPConnectionProvider 115 ) could not instantiate DBCP connection pool
java.lang.NumberFormatException: null
at java.lang.Integer.parseInt(Integer.java:394)
at java.lang.Byte.parseByte(Byte.java:122)
at java.lang.Byte.parseByte(Byte.java:79)
at net.sf.hibernate.connection.DBCPConnectionProvider.configure(DBCPConnectionProvider.java:77)
at net.sf.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:83)
at net.sf.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:64)
at net.sf.hibernate.cfg.Configuration.buildSettings(Configuration.java:1091)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:737)
at com.gm.brownbear.hibernate.ejb.HibernateDemoManyToMany.run(HibernateDemoManyToMany.java:59)
at com.gm.brownbear.hibernate.ejb.HibernateDemoManyToMany.main(HibernateDemoManyToMany.java:30)
HibernateException Could not instantiate DBCP connection pool

3. So, I comment out the dbcp stuff right now. Run the sample code again. I got another error.

Configuration cfg = null;
SessionFactory sf = null;
Session session = null;
try {
cfg = new Configuration()
.addClass(com.gm.brownbear.hibernate.java.Person.class)
.addClass(com.gm.brownbear.hibernate.java.Flight.class)
.addClass(com.gm.brownbear.hibernate.java.Reservation.class);

// create a session object to the database
sf = cfg.buildSessionFactory();
session = sf.openSession();

It stops right here. sf.openSession() return null.

java.lang.NullPointerException
at com.gm.brownbear.hibernate.ejb.HibernateDemoManyToMany.run(HibernateDemoManyToMany.java:158)
at com.gm.brownbear.hibernate.ejb.HibernateDemoManyToMany.main(HibernateDemoManyToMany.java:30)
Exception in thread "main"

Can someone provides me with help? I checked the forum I did not see any thing similar. So, I guess it must something I did not do correctly. I use the hibernte-2.1.1.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 09, 2004 5:43 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
1) Choose one or the other. They are both options you can choose to use to configure the system. (BTW: Don't use both).
2) You have a typo of some form in the DBCP configuration.
3) its not configured correctly.

I suggest you get one (or more) of the examples and have a look at how they are setup. Run them and look at the code etc.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 12, 2004 2:57 am 
Newbie

Joined: Fri Dec 19, 2003 7:15 am
Posts: 4
If you read the source code (net.sf.hibernate.connection.DBCPConnectionProvider), you can find that 8 properties are required to define; otherwise, you will get NumberFormatException.

Here are they:
    hibernate.dbcp.maxActive
    hibernate.dbcp.maxIdle
    hibernate.dbcp.maxWait
    hibernate.dbcp.whenExhaustedAction
    hibernate.dbcp.ps.poolPreparedStatements
    hibernate.dbcp.ps.maxActive
    hibernate.dbcp.ps.maxIdle
    hibernate.dbcp.ps.maxWait
    hibernate.dbcp.ps.whenExhaustedAction


Top
 Profile  
 
 Post subject: Problem running the eg org.hibernate.auction sample code
PostPosted: Mon Jan 12, 2004 3:16 pm 
Newbie

Joined: Mon Dec 01, 2003 7:32 pm
Posts: 7
Thank you David and Jackey. The connection pool configuration is now working.

However, I still have the problem to go through the sessionFactory.openSession(). I use the sample auction program provided with the hibernate download (v. 2.1.1) When I ran the main, the factory.openSession gives me the following error again:

Setting up some test data
java.lang.NoClassDefFoundError: javax/transaction/Synchronization
at net.sf.hibernate.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java:312)
at net.sf.hibernate.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java:325)
at net.sf.hibernate.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java:333)
at org.hibernate.auction.Main.createTestAuctions(Main.java:283)
at org.hibernate.auction.Main.main(Main.java:365)
Exception in thread "main" 

Based on this error trace, can someone point it out to me where I failed to configure correctly? I did not change anything for the auction sample code, by the way. Should I make some changes in order to run the sample code? Thank you in advance.

Qin


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 12, 2004 3:31 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
you dont have jta.jar in your classpath


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 12, 2004 3:44 pm 
Newbie

Joined: Mon Dec 01, 2003 7:32 pm
Posts: 7
Thank you, Gloeglm. It works now.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 12, 2004 5:38 pm 
Newbie

Joined: Mon Dec 01, 2003 7:32 pm
Posts: 7
Now, I have new problems:

I have these code:
Person qin = new Person();
qin.setPersonId(new Integer(8888));
qin.setFirstName("Qin");
qin.setLastName("Ding");

Flight flight = new Flight();
flight.setFlightId(new Integer(1111));
flight.setName("American");
flight.setDepartureUtc(new java.util.Date());
flight.setArrivalUtc(new java.util.Date());

Reservation reservation = new Reservation();
reservation.setReservationId(1234);
reservation.setRegistrationUtc(new java.util.Date());
reservation.setCommentary("Non-smoking");
java.util.Set reservations = new java.util.HashSet();
reservations.add(reservation);
reservation.setPerson(qin);
reservation.setFlight(flight);

qin.setReservations(reservations);
flight.setReservations(reservations);

session.save(flight);
session.save(qin);
session.save(reservation);
session.flush();
session.connection().commit();

I got this msg in the log:
.....
(impl.SessionImpl 2258) executing flush
(persister.EntityPersister 454 ) Inserting entity: [com.gm.brownbear.hibernate.java.Flight#1111]
(impl.BatcherImpl 192 ) about to open: 0 open PreparedStatements, 0 open ResultSets
(hibernate.SQL 223 ) insert into SYSTEM.FLIGHTS (NAME, DEPARTURE_UTC, ARRIVAL_UTC, FLIGHT_ID) values (?, ?, ?, ?)
Hibernate: insert into SYSTEM.FLIGHTS (NAME, DEPARTURE_UTC, ARRIVAL_UTC, FLIGHT_ID) values (?, ?, ?, ?)
(impl.BatcherImpl 227 ) preparing statement
(persister.EntityPersister 389 ) Dehydrating entity: [com.gm.brownbear.hibernate.java.Flight#1111]

It stops here. No data saved in database. I don't see the exception thrown. What went wrong this time?

Qin


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 12, 2004 9:22 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Show the real code (where is tx begining ?)
I recommend you to do
Code:
Tx t = session.beginTransaction();
...
t.commit();
session.close();

_________________
Emmanuel


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