aspose file tools
The moose likes Object Relational Mapping and the fly likes Hibernate and Java: how to save objects in my table? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Databases » Object Relational Mapping
Reply Bookmark "Hibernate and Java: how to save objects in my table?" Watch "Hibernate and Java: how to save objects in my table?" New topic
Author

Hibernate and Java: how to save objects in my table?

Adriano Bellavita
Ranch Hand

Joined: Mar 11, 2010
Posts: 31
Hi all,

I have this simple class in my Java app.



My mysql database look in this way: I have only a table, named "person". It have 4 columns: 'id', 'name', 'petid', 'petname'.

So I want to describe in my xml file that the value of Pet.id has to be stored in person.petid and that Pet.name has to be stored in person.petname.

How can I perform this step?

<?xml version="1.0" encoding="UTF-8"?>
<hibernate-mapping>
<class name="packagename.Person" table="person">
<id name="id" column="id" type="java.lang.String" />
<property name="name" column="name" type="java.lang.String" />
<property name="pet" ??? />
Alexander Bondarev
Greenhorn

Joined: Jan 04, 2012
Posts: 12
Hibernate has <component> XML element which allows you define mapping for embeddable objects whose properties are mapped in the same table as the owning entity's table. See Embedded objects (aka components)
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Hibernate and Java: how to save objects in my table?
 
Similar Threads
Hibernate and MS Access?
Mapping issue in hibernate.cfg.xml
Not able to view the data persisted in the database.
XML file error
Problem in Mapping