tried to make hibernate work with h2 and annotations
This commit is contained in:
parent
793cb2a940
commit
c09e08200f
12
pom.xml
12
pom.xml
|
@ -90,10 +90,16 @@
|
|||
<version>3.6.7.Final</version>
|
||||
</dependency>
|
||||
|
||||
<!--<dependency>-->
|
||||
<!--<groupId>org.hsqldb</groupId>-->
|
||||
<!--<artifactId>hsqldb</artifactId>-->
|
||||
<!--<version>1.8.0.10</version>-->
|
||||
<!--</dependency>-->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.hsqldb</groupId>
|
||||
<artifactId>hsqldb</artifactId>
|
||||
<version>1.8.0.10</version>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<version>1.3.160</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
|
|
@ -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<BuntiDevice> devices = new ArrayList<BuntiDevice>();
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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">
|
||||
|
||||
<jdbc:embedded-database id="dataSource" type="HSQL">
|
||||
<jdbc:embedded-database id="dataSource" type="H2">
|
||||
<jdbc:script location="classpath:init.sql" />
|
||||
</jdbc:embedded-database>
|
||||
|
||||
|
|
|
@ -4,11 +4,19 @@
|
|||
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
|
||||
<hibernate-mapping auto-import="true">
|
||||
|
||||
<class name="de.ctdo.bunti.model.Room" table="rooms" >
|
||||
<id name="id" unsaved-value="0">
|
||||
<generator class="native"/>
|
||||
</id>
|
||||
<property name="name"/>
|
||||
</class>
|
||||
<!--<class name="de.ctdo.bunti.model.Room" table="rooms" >-->
|
||||
<!--<id name="id" unsaved-value="0">-->
|
||||
<!--<generator class="native"/>-->
|
||||
<!--</id>-->
|
||||
<!--<property name="name" column="roomName"/>-->
|
||||
<!--</class>-->
|
||||
|
||||
<!--<class name="de.ctdo.bunti.model.BuntiDevice" table="devices">-->
|
||||
<!--<id name="id" unsaved-value="0">-->
|
||||
<!--<generator class="native"/>-->
|
||||
<!--</id>-->
|
||||
<!--<property name="deviceName"/>-->
|
||||
<!--<property name="picture"/>-->
|
||||
<!--</class>-->
|
||||
|
||||
</hibernate-mapping>
|
|
@ -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');
|
Loading…
Reference in New Issue