This week's book giveaway is in the Reactive Progamming forum.
We're giving away four copies of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams and have Adam Davis on-line!
See this thread for details.
Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming 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
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Mapping join table from Database to hibernate xml file

 
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.


 
Uh oh, we're definitely being carded. Here, show him this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!