mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-15 04:15:50 +00:00
migrated to hsql 2.2.8 and fixed a couple of JPA issues
This commit is contained in:
parent
9f8acc05ad
commit
4e35adb6b0
6 changed files with 23 additions and 27 deletions
2
pom.xml
2
pom.xml
|
@ -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 -->
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
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 {
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
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();
|
||||
|
|
Loading…
Reference in a new issue