-->
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.  [ 2 posts ] 
Author Message
 Post subject: Controlling code generation in Eclipse with hbm.xml file
PostPosted: Tue Aug 12, 2008 5:14 pm 
Newbie

Joined: Wed May 03, 2006 5:09 pm
Posts: 17
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:

3.2

Hibernate tools plugin version:

3.2.2 Beta 1

Mapping documents:

hbmgen.xml

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.bd.benefitsSignup.entity">
     <meta attribute="extends">HistoryEntity</meta>
     <meta attribute="implements">Comparable</meta>
</hibernate-mapping>


Name and version of the database you are using:

MySql 5

Persistence.xml

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Persistence deployment descriptor for dev profile -->
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
             version="1.0">
             
   <persistence-unit name="benefitsSignup">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <jta-data-source>java:/benefitsSignupDatasource</jta-data-source>
     <mapping-file>hbmgen.hmb.xml</mapping-file>
      <properties>
         <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect"/>
         <property name="hibernate.hbm2ddl.auto" value="none"/>
         <property name="hibernate.show_sql" value="true"/>
         <property name="hibernate.format_sql" value="true"/>
         <property name="jboss.entity.manager.factory.jndi.name" value="java:/benefitsSignupEntityManagerFactory"/>
      </properties>
   </persistence-unit>
   
</persistence>


Generated entity example
Code:
package com.bd.benefitsSignup.entity;

@Entity
@Table(name = "address", catalog = "bd")
public class Address implements java.io.Serializable {
.......
}

-----

I've been reading through the documentation for the eclipse tools and was trying to implement using the hbm.xml files to control code generation and make every class inherit from a base class that contains common auditing fields. The documentation (http://docs.jboss.org/tools/2.1.0.Beta1/hibernatetools/html_single/index.html#codegen) shows how to create the hbm.xml file and shows running it via the ant target but doesn't explain how to do this via the Eclipse UI. I have created a console configuration called benefisSignup-ejb and in that I have added the hbmgen.hbm.xml to the Mappings tab. As you can see from the above persistence.xml I have included it there as well.

Unfortunately, it appears that my hbm.xml file is never used because none of the entities are ever generated as extending HistoryEntity or implementing Comparable (just for testing the functionality). Can someone point out to me what I'm doing wrong and/or tell me if there's something I missed about how to do it right?

Thanks,

Drew


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 01, 2008 12:09 pm 
Newbie

Joined: Wed May 31, 2006 7:47 am
Posts: 6
You can generate POJO objects from HBM using the eclipse UI by specifying mappings in the console configuration. Then, in the code generation configuration panel, deselect reverse engineer from JDBC connection and also ensure that you are only generating POJOs in the exporter tab.

Since I have a small application and am too lazy to automate everything, I generate HBM files for new entities, edit them by hand where needed, then generate the POJO files. Its three manual steps but for me its not a big deal as I just have two code generation configuration specified, one for generating HBM files and reverse engineering from the database, and one for generating POJOs from the HBM files. For each of these, I also define a console configuration, one with no mappings specified and one with mappings specified to go along with the two code generation steps respectively. Of course, they use the same xml configuration file to specified a minimalistic session factory.

The only real trick is to not accidently hit the run button on the first step and overwrite any manual changes I have made. A SCM or other code management process can eliminate this danger though.


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