JPA-RS: @OneToOne relationship problem [message #1015901] |
Mon, 04 March 2013 03:48  |
Eclipse User |
|
|
|
I am using GlassFish 3.1.2.2 with EclipseLink 2.5.0 nightly build 02/26 (org.eclipse.persistence.jpars_2.5.0.v20130226-e0971b1.jar). I had success with @OneToMany relationships, but I can't get @OneToOne working. Consider the following entities:
@Entity
public class SomeEntity implements Serializable {
private static final long serialVersionUID = 3578346542105360438L;
@Id
@GeneratedValue
private long id;
@OneToOne(mappedBy="some", orphanRemoval=true, cascade=CascadeType.ALL)
private TestEntity test;
public SomeEntity() {
}
}
@Entity
public class TestEntity implements Serializable {
private static final long serialVersionUID = -6118907654374792523L;
@Id
@GeneratedValue
private long id;
@OneToOne(optional=false)
private SomeEntity some;
public TestEntity() {
}
}
Let's POST SomeEntity:
Response:
{
"id":101,
"_relationships":[
{
"_link":{
"href":"http://localhost:8080/app/persistence/pu/entity/SomeEntity/101/test",
"rel":"test"
}
}
]
}
Let's GET http://localhost:8080/app/persistence/pu/entity/SomeEntity/101/test: the response is '404 - Not Found', and the specified TestEntity is not created. I have also tried to add SomeEntity and TestEntity manually and then retrieving the TestEntity via the link, but even this way I get a 404.
What am I doing wrong? Is this related to weaving?
Quote:Weaving is required for several features to work: providing relationships as links, editing relationships, and dealing with lazy x-1 relationships. Either deploy to a Java EE compliant server or statically weave your classes.
Lazy x-1 relationships are only supported when using the JPA RS default mapping strategy, which returns those mappings as links by using read-only mappings for the JSON/XML support and providing the links through a weaved attribute.
[Updated on: Tue, 05 March 2013 05:36] by Moderator
|
|
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.42222 seconds