-->
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.  [ 5 posts ] 
Author Message
 Post subject: hbm2java problem
PostPosted: Fri May 23, 2008 12:48 pm 
Beginner
Beginner

Joined: Thu Apr 17, 2008 2:03 pm
Posts: 26
Hi,

I am experiencing some problem with hbm2java pojo generation without using ant tools. I use netbeans as my development IDE and testing the implementation on the same IDE.

Code for generating pojos:

public void generatePojos(FileObject revengFile) throws IOException {
HibernateEnvironment env = null;
JDBCMetaDataConfiguration cfg = null;
File f = null;
DataObject revengDataObject = DataObject.find(revengFile);

File confFile = FileUtil.toFile(helper.getConfigurationFile());

try {

cfg = new JDBCMetaDataConfiguration();
OverrideRepository or = new OverrideRepository();
InputStream xmlInputStream = new FileInputStream(FileUtil.toFile(revengFile));
xmlHelper = new XMLHelper();
entityResolver = XMLHelper.DEFAULT_DTD_RESOLVER;
List errors = new ArrayList();

SAXReader saxReader = xmlHelper.createSAXReader("XML InputStream", errors, entityResolver);
org.dom4j.Document doc = saxReader.read(new InputSource(xmlInputStream));
Configuration c = cfg.configure(confFile);
cfg.setReverseEngineeringStrategy(or.getReverseEngineeringStrategy(new DefaultReverseEngineeringStrategy()));
cfg.readFromJDBC();
} catch (Exception e) {
Exceptions.printStackTrace(e);
}

// Generating POJOs
FileObject pkg;
try {
pkg = SourceGroups.getFolderForPackage(helper.getLocation(), helper.getPackageName());
File outputDir = FileUtil.toFile(pkg);
POJOExporter exporter = new POJOExporter(cfg, outputDir);
System.out.println("after creating the pojo exporter");
//exporter.getProperties().setProperty("ejb3", "true");
exporter.start();
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}

hibernate.cfg.xml:

Located at C:\Documents and Settings\gowri\My Documents\NetBeansProjects\WebApplication1\src\java\hibernate.cfg.xml


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="session1">
<property name="hibernate.dialect">org.hibernate.dialect.DerbyDialect</property>
<property name="hibernate.connection.driver_class">org.apache.derby.jdbc.ClientDriver</property>
<property name="hibernate.connection.url">jdbc:derby://localhost:1527/travel</property>
<property name="hibernate.connection.username">travel</property>
<property name="hibernate.connection.password">travel</property>
</session-factory>
</hibernate-configuration>


hibernate.reveng.xml:

located at C:\Documents and Settings\gowri\My Documents\NetBeansProjects\WebApplication1\src\java\hibernate.reveng.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd">
<hibernate-reverse-engineering>
<table-filter exclude="false" match-catalog=".*" match-name="FLIGHT" match-schema=".*"/>
<table-filter exclude="false" match-catalog=".*" match-name="PERSON" match-schema=".*"/>
<table-filter exclude="false" match-catalog=".*" match-name="TRIP" match-schema=".*"/>
<table-filter exclude="false" match-catalog=".*" match-name="TRIPTYPE" match-schema=".*"/>
</hibernate-reverse-engineering>


Now the problems are:

I am getting
org.hibernate.HibernateException: JDBC Driver class not found: org.apache.derby.jdbc.ClientDriver

from cfg.readFromJDBC(). Its asking for derbyclient.jar. I don't have this jar with all the jars that are added for this task (i.e hibernate3, hibernate-tools etc).

If I add derbyclient.jar to the above list, then its generating the pojos for me. The question is why its asking for that jar to be added ? Later on if I want to use mysql instead of javadb, do I have to add mysql jar to the list of jars ?

Note: I have established a proper connection with travel (javadb) database before creating hibernate.cfg.xml.

The second problem is:

Even though I have the ReverseEngineeringStrategy defined in the code, hbm2java is generating pojos for all the database tables in the database connection. I am wondering if you can tell me where I am doing wrong in the code.

Aprreciate your Help.

Thanks - G


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 27, 2008 7:17 am 
Senior
Senior

Joined: Mon Feb 25, 2008 1:48 am
Posts: 191
Location: India
Wrong post... Please ignore this msg

_________________
Sukirtha


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 27, 2008 7:52 am 
Senior
Senior

Joined: Mon Feb 25, 2008 1:48 am
Posts: 191
Location: India
Quote:
Even though I have the ReverseEngineeringStrategy defined in the code, hbm2java is generating pojos for all the database tables in the database connection. I am wondering if you can tell me where I am doing wrong in the code.


That's because in your reverse enginering xml, you have not mentioned which all tables u want to exclude... note that u have set exclude="false" for the tables in the revenge.xml.

_________________
Sukirtha


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 27, 2008 1:16 pm 
Beginner
Beginner

Joined: Thu Apr 17, 2008 2:03 pm
Posts: 26
Hi Sukirtha,

I have added exclude=false for those tables that are selected. Thats how eclipse is also doing. It lists only those tables that are selected in the reveng.xml file. It doesn't show all the tables and add exclude=true for the ones not selected by the user.

Also, do you know why its complaining about the derbyclient.jar ?

Thanks, G


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 28, 2008 8:13 am 
Senior
Senior

Joined: Mon Feb 25, 2008 1:48 am
Posts: 191
Location: India
Hmmm.. I am not sure of how eclipse does it because I have not used eclipse for revenge generation. However, on seeing the revenge file, unless u add exclude="true" for the tables u dont want, the pojos will be generated for all the tables.

Ya u need to add the jar corresponding to database that you want to use. If you don't add, hibernate complains.

_________________
Sukirtha


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