-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: One-to-one association from an embeddable to entity problems
PostPosted: Thu Apr 29, 2010 7:21 am 
Newbie

Joined: Thu Apr 29, 2010 7:08 am
Posts: 1
Hi,

I followed example 3 on the JEE6 documentation http://java.sun.com/javaee/6/docs/api/javax/persistence/OneToOne.html for One-to-one association from an embeddable class to another entity, and get mapping errors on Eclipse:
Image

If I put all three classes in the same Java file, the errors go away. Please help!

Here is the persistance.xml file:

Code:
<?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 are the entity classes:

In Employee.java
Code:
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;
}


In LocationDetails.java
Code:
package com.test;

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

@Embeddable
public class LocationDetails {

int officeNumber;
@OneToOne ParkingSpot parkingSpot;

}


In ParkingSpot.java
Code:
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;
}


Thank you very much in advance.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.