Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: altfatterz/proof-of-concepts
base: a2af8674b1
...
head fork: altfatterz/proof-of-concepts
compare: 77f5077df9
  • 2 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
View
2  spring-hibernate/pom.xml
@@ -7,7 +7,7 @@
<artifactId>spring-hibernate-utility</artifactId>
<version>1.0.0.CI-SNAPSHOT</version>
<packaging>jar</packaging>
- <name>Spring Hibernate Utility</name>
+ <name>spring-hibernate</name>
<url>http://www.springframework.org</url>
<properties>
View
14 spring-hibernate/src/main/java/com/infohubble/learning/Item.java
@@ -1,34 +1,24 @@
package com.infohubble.learning;
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import javax.persistence.ManyToOne;
+import javax.persistence.*;
/**
* An item in an order
*/
@Entity
+@Table(name = "items")
public class Item {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
- @ManyToOne
- private Order order;
-
private String product;
private double price;
private int quantity;
- public Order getOrder() {
- return order;
- }
-
public String getProduct() {
return product;
}
View
12 spring-hibernate/src/main/java/com/infohubble/learning/Order.java
@@ -25,6 +25,18 @@
private String customer;
+ /**
+ * JPA 2.0 unidirectional OneToMany relationship
+ * @JoinColumn can be used on OneToMany to define a foreign key
+ *
+ * The main issue with an unidirectional OneToMany is that the
+ * foreign key is owned by the target object's table, so if the target object has no
+ * knowledge of this foreign key, inserting and updating the value is difficult.
+ * In a unidirectional OneToMany the source object take ownership of the foreign key field,
+ * and is responsible for updating its value.
+ *
+ */
+
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "order_id")
private List<Item> items = new ArrayList<Item>();
View
4 spring-hibernate/src/test/java/com/infohubble/learning/OrderPersistenceTests.java
@@ -43,7 +43,7 @@ public void testSaveAndGet() throws Exception {
session.clear();
Order other = (Order) session.get(Order.class, order.getId());
assertEquals(1, other.getItems().size());
- assertEquals(other, other.getItems().iterator().next().getOrder());
+ //assertEquals(other, other.getItems().iterator().next().getOrder());
}
@Test
@@ -64,7 +64,7 @@ public void testSaveAndFind() throws Exception {
"select o from Order o join o.items i where i.product=:product")
.setString("product", "foo").uniqueResult();
assertEquals(1, other.getItems().size());
- assertEquals(other, other.getItems().iterator().next().getOrder());
+ //assertEquals(other, other.getItems().iterator().next().getOrder());
}
}

No commit comments for this range

Something went wrong with that request. Please try again.