Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

creating .hbm.xml file

 
Sundar Murthi
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can i able to create .hbm.xml file automaticaly using the existing table in the database. through hibernate?

is it possible?
 
Ta Ri Ki Sun
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
have a look at middlegen
 
Peter Laurinec
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There was previous responce about it already.
Have a look at middlegen for Hibernate
[ September 29, 2004: Message edited by: Peter Laurinec ]
 
Madhu Kumar Vatts
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Creating .hbm.xml file automatically

Steps you need to do

1. Get Middlegen
2. Change the build.xml according to the database you chose
3. You can mention which tables you want to generate using the option table in the build.xml file(just closely look at the different ant taks in it)
4. run the ant script using ant middlegen, this will open up a gui in which click hibernate tab, and select the tables you want to generate.
5. Finally click generate, the files will be loaded into the hibernate directory
Let me know if you have questions
 
saranga rao
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi this is how i have done the Creation of HBM file and JavaSource file
and if exist i had even created the tables in database.plesae seee the code


<project name="Domain" default="all" basedir=".">
<property name="Domain" value="Domain" />
<property file="config\hibernate.properties"/>

<property name="ddl.file" value="ddl.sql"/>
<property name="project.com.dir" value ="D:\kazi\Domain\com"/>
<property name="class.root" value="classes"/>
<!-- installation configuration -->
<property name="hibernate_path"
value="D:\kazi\hibernate-3.2"/>
<property name="project.dir"
value="D:\kazi\Domain" />
<property name="database.script.file" value="schema.sql" />
<!-- JDBC connectivity information -->
<property name="database.driver.file"
value="${lib.dir}\mysql-connector-java-3.0.10-stable-bin.jar"/>
<property name="database.driver.classpath"
value="${database.driver.file}"/>
<property name="database.driver"
value="com.mysql.jdbc.Driver"/>
<property name="database.url"
value="jdbc:mysql://localhost/test"/>
<property name="database.userid" value="root"/>
<property name="database.password" value="root123"/>
<property name="database.schema" value="test"/>
<property name="database.dialect" value="net.sf.hibernate.dialect.MySQLDialect"/>

<path id="lib.class.path">
<pathelement path="${basedir}"/>
<fileset dir="${lib.dir}">
<include name="**/*.jar"/>
</fileset>
</path>
<path id="project.classpath">
<fileset dir="${lib.dir}">
<include name="**/*.jar"/>
</fileset>
</path>
<target name="all"
depends="build_tables,schema,hbm2ddl-schema,sql-run-ddl,codegen,compile" />

<target name="schema" description="Generate DB schema from the O/R mapping files" >
<taskdef name="schemaexport" classname="net.sf.hibernate.tool.hbm2ddl.SchemaExportTask"
classpathref="project.classpath">
</taskdef>
<schemaexport properties="${project.dir}/config/hibernate.properties"
quiet="no" text="no" drop="no" delimiter=";">
<fileset dir="${project.dir}">
<include name="**/*.hbm.xml">
</include>
</fileset>
</schemaexport>
</target>
<target name="hbm2ddl-schema" description="Generate DDL from Hibernate mapping" >
<java classname="net.sf.hibernate.tool.hbm2ddl.SchemaExport" fork="true">
<jvmarg value="-Dhibernate.dialect=${database.dialect}"/>
<arg value="mapping/AgencyActivity.hbm.xml"/>
<arg value="mapping/Incident.hbm.xml"/>
<arg value="mapping/HouseholdMemberVehicle.hbm.xml"/>
<arg value="mapping/HouseholdMember.hbm.xml"/>
<arg value="mapping/WarrantyQuestionDetails.hbm.xml"/>
<arg value="mapping/WarrantyQuestions.hbm.xml"/>
<arg value="mapping/CreditHistory.hbm.xml"/>
<arg value="mapping/Discount.hbm.xml"/>
<arg value="mapping/Fee.hbm.xml"/>
<arg value="mapping/UnderwriterActivityLog.hbm.xml"/>
<arg value="mapping/MemberRating.hbm.xml"/>
<arg value="mapping/Payment.hbm.xml"/>
<arg value="mapping/VehicleDiscount.hbm.xml"/>
<arg value="mapping/Claim.hbm.xml"/>
<arg value="mapping/AgencyUser.hbm.xml"/>
<arg value="mapping/Vehicle.hbm.xml"/>
<arg value="mapping/ClaimCoverage.hbm.xml"/>
<arg value="mapping/AdditonalEquipment.hbm.xml"/>
<arg value="mapping/VehicleRating.hbm.xml"/>
<arg value="mapping/AdditionalEquipmentDisclaimer.hbm.xml"/>
<arg value="mapping/Address.hbm.xml"/>
<arg value="mapping/Agency.hbm.xml"/>
<arg value="mapping/InsuranceTransaction.hbm.xml"/>
<arg value="mapping/AgentNotepad.hbm.xml"/>
<arg value="mapping/Alert.hbm.xml"/>
<arg value="mapping/BatchQuote.hbm.xml"/>
<arg value="mapping/Coverage.hbm.xml"/>
<arg value="mapping/InsuredDocument.hbm.xml"/>
<arg value="mapping/Lienholder.hbm.xml"/>
<arg value="mapping/Memo.hbm.xml"/>
<arg value="mapping/RequestHeader.hbm.xml"/>
<arg value="mapping/PriorCarrier.hbm.xml"/>
<arg value="mapping/PolicyEndorsement.hbm.xml"/>
<arg value="mapping/Phone.hbm.xml"/>
<arg value="mapping/MemoMessage.hbm.xml"/>
<arg value="mapping/MemoAssignmentRule.hbm.xml"/>
<arg value="mapping/MemoAttachment.hbm.xml"/>
<arg value="mapping/Status.hbm.xml"/>
<arg value="mapping/UnderwriterDocument.hbm.xml"/>
<arg value="mapping/ValidValue.hbm.xml"/>
<arg value="mapping/SubProducer.hbm.xml"/>
<arg value="mapping/RuleType.hbm.xml"/>
<arg value="mapping/Role.hbm.xml"/>
<arg value="mapping/UserCategory.hbm.xml"/>
<arg value="mapping/RoleAttribute.hbm.xml"/>
<arg value="mapping/Attribute.hbm.xml"/>
<arg value="mapping/RoleElementConfig.hbm.xml"/>
<arg value="mapping/PageElementConfig.hbm.xml"/>
<arg value="mapping/Page.hbm.xml"/>
<classpath refid="lib.class.path"/>
</java>
</target>


it has created every thing jst we have to select which target we want....i had only hbm filesl


Feel free to ask and say.

Regards,
Saranga
 
Sandeep Vaid
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can do this very easily (and using GUI) using Hibernate Tools.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic