From c09e08200fcc74a6a9390d7ad3876ad69a532896 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Ple=C3=9F?= Date: Wed, 21 Mar 2012 21:23:16 +0100 Subject: [PATCH] tried to make hibernate work with h2 and annotations --- pom.xml | 12 ++++++++--- src/main/java/de/ctdo/bunti/model/Room.java | 14 ++++++++++++- .../META-INF/spring/hibernate-beans.xml | 2 +- src/main/resources/bunti.hbm.xml | 20 +++++++++++++------ src/main/resources/init.sql | 15 ++++++-------- 5 files changed, 43 insertions(+), 20 deletions(-) diff --git a/pom.xml b/pom.xml index 29a81ca..39c743e 100644 --- a/pom.xml +++ b/pom.xml @@ -90,10 +90,16 @@ 3.6.7.Final + + + + + + - org.hsqldb - hsqldb - 1.8.0.10 + com.h2database + h2 + 1.3.160 diff --git a/src/main/java/de/ctdo/bunti/model/Room.java b/src/main/java/de/ctdo/bunti/model/Room.java index 8eed3d3..9b20c40 100644 --- a/src/main/java/de/ctdo/bunti/model/Room.java +++ b/src/main/java/de/ctdo/bunti/model/Room.java @@ -1,16 +1,28 @@ package de.ctdo.bunti.model; + +import org.hibernate.annotations.GenericGenerator; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; +@Entity +@Table( name = "rooms" ) public final class Room { private int id; private String name; private List devices = new ArrayList(); + @Id + @GeneratedValue(generator="increment") + @GenericGenerator(name="increment", strategy = "increment") public int getId() { return id; } @@ -37,7 +49,7 @@ public final class Room { public BuntiDevice getDevice(int id) { for (BuntiDevice device: devices) { - if( device.getDeviceId() == id) { + if( device.getId() == id) { return device; } } diff --git a/src/main/resources/META-INF/spring/hibernate-beans.xml b/src/main/resources/META-INF/spring/hibernate-beans.xml index 84e0dac..00616b7 100755 --- a/src/main/resources/META-INF/spring/hibernate-beans.xml +++ b/src/main/resources/META-INF/spring/hibernate-beans.xml @@ -6,7 +6,7 @@ http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd" xmlns:jdbc="http://www.springframework.org/schema/jdbc"> - + diff --git a/src/main/resources/bunti.hbm.xml b/src/main/resources/bunti.hbm.xml index 5fedde1..4f32d5e 100755 --- a/src/main/resources/bunti.hbm.xml +++ b/src/main/resources/bunti.hbm.xml @@ -4,11 +4,19 @@ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> - - - - - - + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/init.sql b/src/main/resources/init.sql index 00e6dc0..64c598a 100755 --- a/src/main/resources/init.sql +++ b/src/main/resources/init.sql @@ -1,12 +1,9 @@ -DROP TABLE DUAL_HIBERNATE_SEQUENCE IF EXISTS -DROP TABLE ROOMS IF EXISTS -DROP TABLE SEQUENCE IF EXISTS - - -CREATE MEMORY TABLE SEQUENCE(SEQ_NAME VARCHAR(50) NOT NULL PRIMARY KEY,SEQ_COUNT NUMERIC(38)) -CREATE MEMORY TABLE ROOMS(ID INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT NULL PRIMARY KEY,NAME VARCHAR(255)) -CREATE MEMORY TABLE DUAL_HIBERNATE_SEQUENCE(ZERO INTEGER) -INSERT INTO SEQUENCE VALUES('SEQ_GEN',0) +drop table rooms if exists; +create table rooms (id integer identity primary key, roomName varchar (255) not null); +insert into rooms (roomName) values ('Raum 1'); +insert into rooms (roomName) values ('Raum 2'); +insert into rooms (roomName) values ('Raum 3'); +insert into rooms (roomName) values ('Raum 4'); \ No newline at end of file