• 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 mapping error

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am having a problem with mapping. I followed the example three given on the following page here line by line.
Note: If I put all three classes in one java file, my IDE(Eclipse) does not give me any errors. However, if I put separate them into three different java files, I get the following errors:



Here is my persistance.xml file...

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="JPA_3">
<provider>org.hibernate.ejb.HibernatePersistence</provider>

<class>com.test.Employee</class>
<class>com.test.LocationDetails</class>
<class>com.test.ParkingSpot</class>

<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>

<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />

<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.username" value="root"/>
<property name="hibernate.connection.password" value="root"/>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost/test_db"/>
</properties>
</persistence-unit>
</persistence>

Here my entity classes...


/****************************************************************************************/
package com.test;

import javax.persistence.Embeddable;
import javax.persistence.OneToOne;

@Embeddable
public class LocationDetails {

int officeNumber;
@OneToOne ParkingSpot parkingSpot;

}


/****************************************************************************************/
package com.test;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToOne;

@Entity
public class ParkingSpot {

@Id int id;
String garage;
@OneToOne(mappedBy="location.parkingSpot") Employee assignedTo;

}


/****************************************************************************************/
package com.test;

import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.Id;

@Entity
public class Employee {

@Id int id;
@Embedded LocationDetails location;


}

/****************************************************************************************/



Thank you very much for your help.
 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Instead of location.parkingSpot did you mean locationDetails.parkingSpot ?
 
Mino Petite
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Craig,

Thanks for taking the time to reply.
But base on the example giving on this documentation, Example 3 Here they have it as location.parkingSpot, and even if i changed i get a similar error message.

thanks again...
 
Craig Taylor
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're right ... I was looking at the class definitions incorrectly.

Off-hand I'm not sure what the issue is ... Later tonight I'll try to recreate your project and see what I find.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic