This week's giveaway is in the JDBC forum.
We're giving away four copies of Java Database Connections & Transactions (e-book only) and have Marco Behler on-line!
See this thread for details.
Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Mapping join table from Database to hibernate xml file  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have designed database in mysql. I know how to create .hbm.xml file in hibernate but don't know whether I will have to map the foreign key relation in the hibernate xml file also. If yes,
1. how do I do that?
2. how do I map a join table to hibernate mapping file
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I understand your question correctly, you want to map your tables using hibernate JPA.
I wish, if so then I will use an IDE (I will use Netbeans) to demonstrate it quickly:
1. From >File select >New file…
2. Select “Hibernate” Category from left side
3. Choose First item “Hibernate Configuration Wizard ” and Click “Next”
4. Netbeans will suggest “hibernate.cfg” click next
5. Select your Datasource.
6. Change first item to “New Database Connection”
7. New dialogue will appear, select MySQL and highlight the driver library
8. Click next, Customize your connection
9. Do not forget to check “Remember password”
10. Finish the wizard
11. From >File select >New file…
12. Select “Hibernate” Category from left side
13. Choose First item “Hibernate Reverse Engineering” and Click “Next” and finish the wizard
14. From >File select >New file…
15. Select “Hibernate” Category from left side
16. Choose First item “Hibernate Mapping Files and POJO from database” and Click “Next” and finish the wizard.
Joined tables will shown as this example: HC_CITY
Joined table is in bold.
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Aug 1, 2015 9:46:07 AM by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
<class name="mapping.Hccity" table="HCCITY" schema="HCDB">
<id name="cityid" type="long">
<column name="CITYID" precision="22" scale="0" />
<generator class="sequence"><param name="sequence">HCCITY_SQ</param></generator>
</id>
<property name="cityname" type="string">
<column name="CITYNAME" length="200" />
</property>
<property name="deleted" type="boolean">
<column name="DELETED" precision="1" scale="0" />
</property>
<set name="hcpersonaddresses" inverse="true">
<key>
<column name="CITYID" precision="22" scale="0" />
</key>
<one-to-many class="mapping.Hcpersonaddress" />
</set>

</class>
</hibernate-mapping>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
I wish this can help, Good Luck.


 
Your mother was a hamster and your father was a tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!