• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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" ??? />
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
 
reply
    Bookmark Topic Watch Topic
  • New Topic