JPA-RS: @OneToOne relationship problem [message #1015901] |
Mon, 04 March 2013 08:48 |
Daniel Szalay Messages: 15 Registered: February 2013 |
Junior Member |
|
|
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 10:36] Report message to a moderator
|
|
|
|
|
|
|
|
Re: JPA-RS: @OneToOne relationship problem [message #1018288 is a reply to message #1018255] |
Wed, 13 March 2013 15:05 |
Daniel Szalay Messages: 15 Registered: February 2013 |
Junior Member |
|
|
The relationship is corrupted before and after redeploy too! However the relationship link magically works before redeploy; I guess it is cached in the persistence unit, but not persisted to database.
So to use the terminology from my original example: If I check the contents of the TESTENTITY table, I can see that the related instance has been created, but it's foreign key SOME_ID is NULL.
Tested with:
- EclipseLink 2.5.0 Nightly 20130312
- EclipseLink 2.5.0 Nightly 20130313
[Updated on: Wed, 13 March 2013 15:25] Report message to a moderator
|
|
|
|
Re: JPA-RS: @OneToOne relationship problem [message #1018740 is a reply to message #1018386] |
Thu, 14 March 2013 11:47 |
Daniel Szalay Messages: 15 Registered: February 2013 |
Junior Member |
|
|
Thanks, it works this way. However my entities are valid, so it should work too right?
EDIT: If I do it this way, than it does not work the other way around, meaning: I GET the related entity, and from there if I try to GET the relationship link of the owner, then I get 404. So for me it seems like bidirectional relationships do not work correctly at the moment.
[Updated on: Thu, 14 March 2013 16:19] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.04034 seconds