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