temporary persistence work

This commit is contained in:
eugenp 2013-05-18 17:28:25 +03:00
parent f50f4eb6a6
commit c1dce2cd59
3 changed files with 47 additions and 0 deletions

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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();
}
}