-->
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.  [ 1 post ] 
Author Message
 Post subject: Converting *.hbm.xml file to Java Code file question!
PostPosted: Thu Aug 27, 2009 12:11 am 
Newbie

Joined: Thu Nov 13, 2008 1:46 am
Posts: 6
Within Hibernate 2, I am attempting to implement the Configuration and Mappings object
in a Java class so that I don't use hibernate.cfg.xml and Object.hbm.xml
files. I have succeeded with hibernate.cfg.xml:

//***************************************************************************************

import org.hibernate.cfg.*;
import org.hibernate.util.*;

Configuration configuration = new Configuration();
Properties properties = new Properties();
properties.setProperty("hibernate.connection.driver_class","com.mysql.jdbc.Driver");
properties.setProperty("hibernate.connection.url","jdbc:mysql://localhost/hibernatetutorial");
properties.setProperty("hibernate.connection.username","root");
properties.setProperty("hibernate.connection.password","password");
properties.setProperty("hibernate.connection.pool_size","10");
properties.setProperty("show_sql","true");
properties.setProperty("dialect","org.hibernate.dialect.MySQLDialect");
properties.setProperty("hibernate.hbm2ddl.auto","update");
configuration.addProperties(properties);

//...suspected object mapping code
Mappings mappings = configuration.createMappings();
HibernateObjectMapping object = new HibernateObjectMapping();
object.setMappingsObject();
Mappings = object.getMappingsObject();
object.buildMappings();
//...

//....hbm.xml referencing code.
SessionFactory factory = configuration.configure().buildSessionFactory();
Session session = factory.getCurrentSession();
Object object = (Object)session.load(Object.class,1);
//...

// hibernate away...
session.save(object);
factory.close();
//***************************************************************************************

but am having trouble with Object.hbm.xml, upon the Mappings Object.
I want the contents for these xml files in memory from Java code, not the XML files.
Ie. I DO want to hard configuration and mappings in Java code, as per my style above.
I know about what the tutorial says at

http://docs.jboss.org/hibernate/stable/ ... asses.html

and while the javadoc is some help
however, I still struggle to see through this, one xml tag/java code line at a time.
Could someone kindly advise/point me in the right direction
for programming of an Object.hbm.xml in java code?
In other terms, how do I successfully relate in what
one sees, in, say:

//*********************************************************88
- <hibernate-mapping>
- <class name="events.Person" table="PERSON">
- <id name="id" column="PERSON_ID">
<generator class="native" />
</id>
<property name="age" />
<property name="firstname" />
<property name="lastname" />
</class>
</hibernate-mapping>
//*********************************************************88

by programming with the Mappings class, and any other(s)?
[I do NOT want to know how to convert Object.hbm.xml to a Pojo Class,
rather I want to convert the mapping instructions themselves.]

-Is it true that using jdk 5 and up annotations hibernate
removes the need for *.hbm.xml?

-If so, does my Configuration/properties approach still remain valid for hibernate
with annotations? How do I specify things like

<session-factory>
<mapping package = "Name"/>
<mapping class = "Fred"/>
<session-factory>

using Java programming?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.