temporary persistence work
This commit is contained in:
parent
f50f4eb6a6
commit
c1dce2cd59
|
@ -3,8 +3,11 @@ package org.baeldung.spring.persistence.model;
|
|||
import java.io.Serializable;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.PrimaryKeyJoinColumn;
|
||||
|
||||
@Entity
|
||||
public class Child implements Serializable {
|
||||
|
@ -13,6 +16,10 @@ public class Child implements Serializable {
|
|||
@GeneratedValue
|
||||
private long id;
|
||||
|
||||
@OneToOne(fetch = FetchType.LAZY)
|
||||
@PrimaryKeyJoinColumn
|
||||
private Parent parent;
|
||||
|
||||
public Child() {
|
||||
super();
|
||||
}
|
||||
|
@ -27,4 +34,12 @@ public class Child implements Serializable {
|
|||
this.id = id;
|
||||
}
|
||||
|
||||
public Parent getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public void setParent(final Parent parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,9 +2,12 @@ package org.baeldung.spring.persistence.model;
|
|||
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToOne;
|
||||
|
||||
@Entity
|
||||
public class Parent implements Serializable {
|
||||
|
@ -13,10 +16,19 @@ public class Parent implements Serializable {
|
|||
@GeneratedValue
|
||||
private long id;
|
||||
|
||||
@OneToOne(fetch = FetchType.LAZY, mappedBy = "parent", cascade = CascadeType.ALL)
|
||||
private Child child;
|
||||
|
||||
public Parent() {
|
||||
super();
|
||||
}
|
||||
|
||||
public Parent(final Child child) {
|
||||
super();
|
||||
|
||||
this.child = child;
|
||||
}
|
||||
|
||||
// API
|
||||
|
||||
public long getId() {
|
||||
|
@ -27,4 +39,12 @@ public class Parent implements Serializable {
|
|||
this.id = id;
|
||||
}
|
||||
|
||||
public Child getChild() {
|
||||
return child;
|
||||
}
|
||||
|
||||
public void setChild(final Child child) {
|
||||
this.child = child;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package org.baeldung.spring.persistence.service;
|
||||
|
||||
import org.baeldung.spring.persistence.config.PersistenceConfig;
|
||||
import org.baeldung.spring.persistence.model.Child;
|
||||
import org.baeldung.spring.persistence.model.Parent;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -25,4 +27,14 @@ public class ParentServicePersistenceIntegrationTest {
|
|||
//
|
||||
}
|
||||
|
||||
@Test
|
||||
public final void whenEntityIsCreated_thenNoExceptions() {
|
||||
final Child childEntity = new Child();
|
||||
childService.create(childEntity);
|
||||
|
||||
service.create(new Parent(childEntity));
|
||||
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue