-->
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.  [ 6 posts ] 
Author Message
 Post subject: Must be pojo and file.hmb.xml in the same package?
PostPosted: Fri May 13, 2005 6:30 am 
Newbie

Joined: Tue May 10, 2005 10:54 am
Posts: 16
Location: Italy
Hibernate version: Hibernate 2.1

Hi, I'm new in hibernate.
I've create my first application with hibernate and it goes.
But now I've a question ... with hibernate mapping file and pojo must be in the same package?
I'd like have 2 package:
data.xml with all file .hbm.xml and
data.db with all pojo

If I try I've an error: the sistem doesn't find file.hbm.xml in package data.db. ...And in fact they aren't there...
Where can I tell in what package search my mapping file?
In hibernate.cfg.xml?

Thanks


Top
 Profile  
 
 Post subject: Re: Must be pojo and file.hmb.xml in the same package?
PostPosted: Fri May 13, 2005 6:53 am 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
mariella wrote:
Hibernate version: Hibernate 2.1

Hi, I'm new in hibernate.
I've create my first application with hibernate and it goes.
But now I've a question ... with hibernate mapping file and pojo must be in the same package?
I'd like have 2 package:
data.xml with all file .hbm.xml and
data.db with all pojo

If I try I've an error: the sistem doesn't find file.hbm.xml in package data.db. ...And in fact they aren't there...
Where can I tell in what package search my mapping file?
In hibernate.cfg.xml?

Thanks


How are you configuring your SessionFactory ?
If you're using the cfg.addClass(MyClass.class) then it will expect the mapping file to be in the same package. But if you use cfg.addResource("MyClass.hbm.xml") you specify the package of the pojo inside this file so you should be okay. Or,as you eluded to, if you specify the hbm files in the hibernate.cfg.xml, you should also be okay as long as the resource mappings point to the hbm files.

<mapping resource="data/xml/MyClass.hbm.xml"/>

All that said, I think most users prefer to keep these in the same package. It makes changing things easier since they're both in the same folder in the filesystem.

And if you're truely new to hibernate, I'd recommend using the 3.0x release.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 13, 2005 6:53 am 
Newbie

Joined: Wed Mar 30, 2005 10:11 am
Posts: 2
Yep you can declare them in hibernate.cfg for example:

<session-factory>
<mapping
resource="com/yourco/blah/blah/MyMapping.hbm.xml"/>
</session-factory>


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 13, 2005 6:54 am 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
It is possible.You have to set absolute path for hbm.xml in .cfg.xml

regards


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 13, 2005 10:00 am 
Newbie

Joined: Tue May 10, 2005 10:54 am
Posts: 16
Location: Italy
I've a similary error:


Code:
15:48:29,068  INFO Environment:483 - Hibernate 2.1.8
15:48:29,158  INFO Environment:517 - loaded properties from resource hibernate.properties: {hibernate.connection.password=, hibernate.jdbc.batch_versioned_data=true, hibernate.query.substitutions=true 1, false 0, yes 'Y', no 'N', hibernate.cache.region_prefix=hibernate.test, hibernate.show_sql=true, hibernate.proxool.pool_alias=pool1, hibernate.c3p0.max_statements=0, hibernate.jdbc.batch_size=0, hibernate.cache.use_query_cache=true, hibernate.jdbc.use_streams_for_binary=true, hibernate.max_fetch_depth=1, hibernate.connection.pool_size=1, hibernate.connection.username=root, hibernate.connection.driver_class=com.mysql.jdbc.Driver, hibernate.cache.provider_class=net.sf.hibernate.cache.EhCacheProvider, hibernate.cglib.use_reflection_optimizer=true, hibernate.dialect=net.sf.hibernate.dialect.MySQLDialect, hibernate.connection.url=jdbc:mysql://localhost/progetto}
15:48:29,218  INFO Environment:542 - using java.io streams to persist binary types
15:48:29,218  INFO Environment:543 - using CGLIB reflection optimizer
15:48:29,729  INFO Environment:572 - using JDK 1.4 java.sql.Timestamp handling
15:48:29,779  INFO Configuration:332 - Mapping resource: com.omeopatici.dati.xml.Utente.hbm.xml
net.sf.hibernate.MappingException: Resource: com.omeopatici.dati.xml.Utente.hbm.xml not found
   at net.sf.hibernate.cfg.Configuration.addResource(Configuration.java:335)
   at com.omeopatici.dati.db.operazioni.GestioneUtente.<init>(GestioneUtente.java:46)
   at com.omeopatici.dati.db.solotestatute.Accesso.Ins_actionPerformed(Accesso.java:105)
   at com.omeopatici.dati.db.solotestatute.Accesso$1.actionPerformed(Accesso.java:85)
   at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1764)
   at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1817)
   at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:419)
   at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:257)
   at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)
   at java.awt.Component.processMouseEvent(Component.java:5134)
   at java.awt.Component.processEvent(Component.java:4931)
   at java.awt.Container.processEvent(Container.java:1566)
   at java.awt.Component.dispatchEventImpl(Component.java:3639)
   at java.awt.Container.dispatchEventImpl(Container.java:1623)
   at java.awt.Component.dispatchEvent(Component.java:3480)
   at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3450)
   at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3165)
   at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3095)
   at java.awt.Container.dispatchEventImpl(Container.java:1609)
   at java.awt.Window.dispatchEventImpl(Window.java:1590)
   at java.awt.Component.dispatchEvent(Component.java:3480)
   at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)
   at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:197)
   at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
   at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)
15:48:32,593  INFO Configuration:351 - Mapping resource: com/omeopatici/dati/db/struttureDati/Gruppo.hbm.xml
net.sf.hibernate.MappingException: Resource: com/omeopatici/dati/db/struttureDati/Gruppo.hbm.xml not found
   at net.sf.hibernate.cfg.Configuration.addClass(Configuration.java:353)
   at com.omeopatici.dati.db.operazioni.Autenticazione.Autentica(Autenticazione.java:37)
   at com.omeopatici.dati.db.solotestatute.Inizio.<init>(Inizio.java:52)
   at com.omeopatici.dati.db.solotestatute.Inizio.main(Inizio.java:67)
java.lang.NullPointerException
   at com.omeopatici.dati.db.operazioni.Autenticazione.Autentica(Autenticazione.java:76)
   at com.omeopatici.dati.db.solotestatute.Inizio.<init>(Inizio.java:52)
   at com.omeopatici.dati.db.solotestatute.Inizio.main(Inizio.java:67)


My file
Code:
cfg=new Configuration()
.addResource("com.omeopatici.dati.xml.Utente.hbm.xml")
.addResource("com.omeopatici.dati.xml.Gruppo.hbm.xml")
.addResource("com.omeopatici.dati.xml.Autorizzazioni.hbm.xml")
.setProperty(Environment.HBM2DDL_AUTO, "create");
      
sf = cfg.buildSessionFactory();



hibernate.cfg
Code:
<mapping resource="com/omeopatici/dati/xml/Utente.hbm.xml"/>
<mapping resource="com/omeopatici/dati/xml/Gruppo.hbm.xml"/>
<mapping resource="com/omeopatici/dati/xml/Autorizzazioni.hbm.xml"/>



What I miss?
Where's wrong?


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 13, 2005 11:01 am 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
your classpath isn't good - add directory where is com

regards


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