Skip to content
Snippets Groups Projects
Commit 4e35adb6 authored by Mic's avatar Mic
Browse files

migrated to hsql 2.2.8 and fixed a couple of JPA issues

parent 9f8acc05
No related branches found
No related tags found
No related merge requests found
......@@ -85,7 +85,7 @@
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>1.8.0.10</version>
<version>2.2.8</version>
<scope>runtime</scope>
</dependency>
<!-- MySQL JDBC Connector -->
......
package org.springframework.samples.petclinic;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
......@@ -12,7 +14,7 @@ import javax.persistence.MappedSuperclass;
*/
@MappedSuperclass
public class BaseEntity {
@Id
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
protected Integer id;
......
......@@ -7,6 +7,8 @@ import java.util.List;
import java.util.Set;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlElement;
......@@ -25,7 +27,8 @@ import org.springframework.beans.support.PropertyComparator;
@Entity @Table(name="vets")
public class Vet extends Person {
@ManyToMany
@ManyToMany @JoinTable (name="vet_specialties",joinColumns = @JoinColumn(name = "vet_id"),
inverseJoinColumns= @JoinColumn(name = "specialty_id"))
private Set<Specialty> specialties;
......
......@@ -24,6 +24,7 @@ import org.springframework.dao.DataAccessException;
* @author Mike Keith
* @author Rod Johnson
* @author Sam Brannen
* @author Michael Isvy
* @since 22.4.2006
*/
@Repository
......@@ -65,27 +66,16 @@ public class EntityManagerClinic implements Clinic {
}
public void storeOwner(Owner owner) {
// Consider returning the persistent object here, for exposing
// a newly assigned id using any persistence provider...
Owner merged = this.em.merge(owner);
this.em.flush();
owner.setId(merged.getId());
this.em.merge(owner);
}
public void storePet(Pet pet) {
// Consider returning the persistent object here, for exposing
// a newly assigned id using any persistence provider...
Pet merged = this.em.merge(pet);
this.em.flush();
pet.setId(merged.getId());
this.em.merge(pet);
}
public void storeVisit(Visit visit) {
// Consider returning the persistent object here, for exposing
// a newly assigned id using any persistence provider...
Visit merged = this.em.merge(visit);
this.em.flush();
visit.setId(merged.getId());
this.em.merge(visit);
}
public void deletePet(int id) throws DataAccessException {
......
CREATE TABLE vets (
id INTEGER NOT NULL IDENTITY PRIMARY KEY,
id INTEGER IDENTITY PRIMARY KEY,
first_name VARCHAR(30),
last_name VARCHAR(30)
);
CREATE INDEX vets_last_name ON vets(last_name);
CREATE TABLE specialties (
id INTEGER NOT NULL IDENTITY PRIMARY KEY,
id INTEGER IDENTITY PRIMARY KEY,
name VARCHAR(80)
);
CREATE INDEX specialties_name ON specialties(name);
......@@ -19,13 +19,13 @@ alter table vet_specialties add constraint fk_vet_specialties_vets foreign key (
alter table vet_specialties add constraint fk_vet_specialties_specialties foreign key (specialty_id) references specialties(id);
CREATE TABLE types (
id INTEGER NOT NULL IDENTITY PRIMARY KEY,
id INTEGER IDENTITY PRIMARY KEY,
name VARCHAR(80)
);
CREATE INDEX types_name ON types(name);
CREATE TABLE owners (
id INTEGER NOT NULL IDENTITY PRIMARY KEY,
id INTEGER IDENTITY PRIMARY KEY,
first_name VARCHAR(30),
last_name VARCHAR(30),
address VARCHAR(255),
......@@ -35,7 +35,7 @@ CREATE TABLE owners (
CREATE INDEX owners_last_name ON owners(last_name);
CREATE TABLE pets (
id INTEGER NOT NULL IDENTITY PRIMARY KEY,
id INTEGER IDENTITY PRIMARY KEY,
name VARCHAR(30),
birth_date DATE,
type_id INTEGER NOT NULL,
......@@ -46,7 +46,7 @@ alter table pets add constraint fk_pets_types foreign key (type_id) references t
CREATE INDEX pets_name ON pets(name);
CREATE TABLE visits (
id INTEGER NOT NULL IDENTITY PRIMARY KEY,
id INTEGER IDENTITY PRIMARY KEY,
pet_id INTEGER NOT NULL,
visit_date DATE,
description VARCHAR(255)
......
......@@ -23,6 +23,7 @@ import org.springframework.samples.petclinic.Visit;
import org.springframework.samples.petclinic.util.EntityUtils;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
/**
* <p>
......@@ -65,7 +66,7 @@ public class JpaClinicTests {
}
@Test
@Test @Transactional
public void testGetVets() {
Collection<Vet> vets = this.clinic.getVets();
......@@ -141,7 +142,7 @@ public class JpaClinicTests {
assertEquals("Peter", p6.getOwner().getFirstName());
}
@Test
@Test @Transactional
public void testInsertPet() {
Owner o6 = this.clinic.findOwner(6);
int found = o6.getPets().size();
......@@ -168,7 +169,7 @@ public class JpaClinicTests {
assertEquals(old + "X", p7.getName());
}
@Test
@Test @Transactional
public void testInsertVisit() {
Pet p7 = this.clinic.findPet(7);
int found = p7.getVisits().size();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment