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: Hibernate Configuraion Problem
PostPosted: Thu Feb 10, 2005 6:58 am 
Newbie

Joined: Tue Feb 08, 2005 12:04 pm
Posts: 11
Location: London
I have used middlegen plugin for eclipse to generate mapping xml and java classes. But when im trying to write code to persist java class, its giving me error on hibernate.cfg.xml.

My entries of this xml are as follows

<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
<hibernate-configuration>
<session-factory >
<property name="show_sql">true</property>
<mapping resource="org/ultimania/dto/Contact.hbm.xml"/>
<mapping resource="org/ultimania/dto/Person.hbm.xml"/>
<mapping resource="org/ultimania/dto/ContactMethod.hbm.xml"/>
<mapping resource="org/ultimania/dto/EntityType.hbm.xml"/>
<mapping resource="org/ultimania/dto/Gender.hbm.xml"/>
</session-factory>
</hibernate-configuration>

And java code is :

Configuration cfg = new Configuration()
.addClass(org.ultimania.dto.Contact.class)
.addClass(org.ultimania.dto.Person.class)
.addClass(org.ultimania.dto.ContactMethod.class)
.addClass(org.ultimania.dto.Gender.class)
.addClass(org.ultimania.dto.EntityType.class);

SessionFactory factory = cfg.configure().buildSessionFactory();
Session session = factory.openSession();
Transaction t = session.beginTransaction();
session.save(c);
t.commit();
session.close();

Please reply, and If you need to know anything i'll provide.
Thanx

///////////////////////// STACK TRACE //////////////////////////////////

log4j:ERROR setFile(null,true) call failed.
java.io.FileNotFoundException: log\test.log (The system cannot find the path specified)
at java.io.FileOutputStream.openAppend(Native Method)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at org.apache.log4j.FileAppender.setFile(FileAppender.java:272)
at org.apache.log4j.FileAppender.activateOptions(FileAppender.java:151)
at org.apache.log4j.config.PropertySetter.activate(PropertySetter.java:247)
at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:123)
at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:87)
at org.apache.log4j.PropertyConfigurator.parseAppender(PropertyConfigurator.java:645)
at org.apache.log4j.PropertyConfigurator.parseCategory(PropertyConfigurator.java:603)
at org.apache.log4j.PropertyConfigurator.configureRootCategory(PropertyConfigurator.java:500)
at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:406)
at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:432)
at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:460)
at org.apache.log4j.LogManager.<clinit>(LogManager.java:113)
at org.apache.log4j.Logger.getLogger(Logger.java:85)
at org.apache.commons.logging.impl.Log4JLogger.getLogger(Log4JLogger.java:229)
at org.apache.commons.logging.impl.Log4JLogger.<init>(Log4JLogger.java:65)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:529)
at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:235)
at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:209)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:351)
at net.sf.hibernate.cfg.Configuration.<clinit>(Configuration.java:95)
at org.ultimania.dto.Manager.main(Manager.java:30)
net.sf.hibernate.HibernateException: problem parsing configuration/hibernate.cfg.xml
at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:972)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:911)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:897)
at org.ultimania.dto.Manager.main(Manager.java:37)
Caused by: net.sf.hibernate.MappingException: invalid configuration
at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:968)
... 3 more
Caused by: org.xml.sax.SAXParseException: The content of element type "session-factory" is incomplete, it must match "(property*,mapping+,(class-cache|collection-cache|jcs-class-cache|jcs-collection-cache)*)".
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.dtd.XMLDTDValidator.handleEndElement(Unknown Source)
at org.apache.xerces.impl.dtd.XMLDTDValidator.endElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.dom4j.io.SAXReader.read(SAXReader.java:339)
at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:967)
... 3 more
Exception in thread "main"

_________________
Regards,

Ahsan


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 10, 2005 7:14 am 
Beginner
Beginner

Joined: Tue Jan 11, 2005 5:50 am
Posts: 43
Location: Zurich (Suisse)
Hello Ahsan

Code:
.addClass(org.ultimania.dto.Contact.class)
.addClass(org.ultimania.dto.Person.class)
.addClass(org.ultimania.dto.ContactMethod.class)
.addClass(org.ultimania.dto.Gender.class)
.addClass(org.ultimania.dto.EntityType.class);


Remove these lines of code, the mapping is already declared in the hibernate.cfg.xml, the other mapping is unnecessary.

You also forgot to provide the basic settings, like database url, password, ...

You find examples in the manual, the docs.


Regards
Tarik


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 10, 2005 7:30 am 
Newbie

Joined: Tue Feb 08, 2005 12:04 pm
Posts: 11
Location: London
Thanks very much, Now this error has resolved but still a new error is there about JDBC. I think MiddlegeN deals with all Databse stuff then why is that?

////////////////////// STACK TRACE //////////////////////
java.lang.UnsupportedOperationException: The user must supply a JDBC connection
at net.sf.hibernate.connection.UserSuppliedConnectionProvider.getConnection(UserSuppliedConnectionProvider.java:32)
at net.sf.hibernate.impl.BatcherImpl.openConnection(BatcherImpl.java:292)
at net.sf.hibernate.impl.SessionImpl.connect(SessionImpl.java:3373)
at net.sf.hibernate.impl.SessionImpl.connection(SessionImpl.java:3333)
at net.sf.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:40)
at net.sf.hibernate.transaction.JDBCTransactionFactory.beginTransaction(JDBCTransactionFactory.java:19)
at net.sf.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:2252)
at org.ultimania.dto.Manager.main(Manager.java:36)

_________________
Regards,

Ahsan


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 10, 2005 7:42 am 
Newbie

Joined: Tue Feb 08, 2005 12:04 pm
Posts: 11
Location: London
And if im removing

Transaction t = session.beginTransaction();

then JDBC Exception is not coming but this error is here. I duno why?


log4j:ERROR setFile(null,true) call failed.
java.io.FileNotFoundException: log\test.log (The system cannot find the path specified)
at java.io.FileOutputStream.openAppend(Native Method)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)

Thanx

_________________
Regards,

Ahsan


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 10, 2005 7:48 am 
Beginner
Beginner

Joined: Tue Jan 11, 2005 5:50 am
Posts: 43
Location: Zurich (Suisse)
Middlegen is not able to know to what database under which username/password it has to connect, this is that what is missing. So you either do that in hibernate.cfg.xml or you set it in the ant task as a property if you came from ant.

Regards
Tarik


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 10, 2005 8:17 am 
Newbie

Joined: Tue Feb 08, 2005 12:04 pm
Posts: 11
Location: London
Thanx,

Well For the time being Iv done it through Hibernate.properties file. But now problem is this that Im using FIREBIRD on backend. Everything is OK now.

But still even my code is persisting the object, after that its giving me an exception, plz tell me why is that?


//////////////////// STACK TRACE ////////////////////////////////////

log4j:ERROR setFile(null,true) call failed.
java.io.FileNotFoundException: log\test.log (The system cannot find the path specified)

at java.io.FileOutputStream.openAppend(Native Method)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at org.apache.log4j.FileAppender.setFile(FileAppender.java:272)
at org.apache.log4j.FileAppender.activateOptions(FileAppender.java:151)
at org.apache.log4j.config.PropertySetter.activate(PropertySetter.java:247)
at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:123)
at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:87)
at org.apache.log4j.PropertyConfigurator.parseAppender(PropertyConfigurator.java:645)
at org.apache.log4j.PropertyConfigurator.parseCategory(PropertyConfigurator.java:603)
at org.apache.log4j.PropertyConfigurator.configureRootCategory(PropertyConfigurator.java:500)
at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:406)
at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:432)
at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:460)
at org.apache.log4j.LogManager.<clinit>(LogManager.java:113)
at org.apache.log4j.Logger.getLogger(Logger.java:85)
at org.apache.commons.logging.impl.Log4JLogger.getLogger(Log4JLogger.java:229)
at org.apache.commons.logging.impl.Log4JLogger.<init>(Log4JLogger.java:65)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:529)
at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:235)
at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:209)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:351)
at net.sf.hibernate.cfg.Configuration.<clinit>(Configuration.java:95)
at org.ultimania.dto.Manager.main(Manager.java:30)

Thanx,

_________________
Regards,

Ahsan


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 10, 2005 9:08 am 
Beginner
Beginner

Joined: Tue Jan 11, 2005 5:50 am
Posts: 43
Location: Zurich (Suisse)
Log4J does not find the file test.log on the path log/test.log as stated in the message. So you should create a folder and a file as you have specified in the log4j.xml.

Regards
Tarik


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 10, 2005 10:40 am 
Newbie

Joined: Tue Feb 08, 2005 12:04 pm
Posts: 11
Location: London
Thank you very much Tarik,

Its working now, Im really gratefull. I was just testing Hibernate first time, As its working now, So Iv to develop complete persistence layer using hibernate and deploy over JBoss and I'll be in touch, in case of any problem. Thanx once again.

Wish u best of luck

_________________
Regards,

Ahsan


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 10, 2005 10:50 am 
Beginner
Beginner

Joined: Tue Jan 11, 2005 5:50 am
Posts: 43
Location: Zurich (Suisse)
You are welcome :-)

Regards
Tarik


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.