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>
|
<version>3.6.7.Final</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!--<dependency>-->
|
||||||
|
<!--<groupId>org.hsqldb</groupId>-->
|
||||||
|
<!--<artifactId>hsqldb</artifactId>-->
|
||||||
|
<!--<version>1.8.0.10</version>-->
|
||||||
|
<!--</dependency>-->
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hsqldb</groupId>
|
<groupId>com.h2database</groupId>
|
||||||
<artifactId>hsqldb</artifactId>
|
<artifactId>h2</artifactId>
|
||||||
<version>1.8.0.10</version>
|
<version>1.3.160</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,28 @@
|
||||||
package de.ctdo.bunti.model;
|
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.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table( name = "rooms" )
|
||||||
public final class Room {
|
public final class Room {
|
||||||
|
|
||||||
private int id;
|
private int id;
|
||||||
private String name;
|
private String name;
|
||||||
private List<BuntiDevice> devices = new ArrayList<BuntiDevice>();
|
private List<BuntiDevice> devices = new ArrayList<BuntiDevice>();
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(generator="increment")
|
||||||
|
@GenericGenerator(name="increment", strategy = "increment")
|
||||||
public int getId() {
|
public int getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
@ -37,7 +49,7 @@ public final class Room {
|
||||||
|
|
||||||
public BuntiDevice getDevice(int id) {
|
public BuntiDevice getDevice(int id) {
|
||||||
for (BuntiDevice device: devices) {
|
for (BuntiDevice device: devices) {
|
||||||
if( device.getDeviceId() == id) {
|
if( device.getId() == id) {
|
||||||
return device;
|
return device;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd"
|
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd"
|
||||||
xmlns:jdbc="http://www.springframework.org/schema/jdbc">
|
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:script location="classpath:init.sql" />
|
||||||
</jdbc:embedded-database>
|
</jdbc:embedded-database>
|
||||||
|
|
||||||
|
|
|
@ -4,11 +4,19 @@
|
||||||
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
|
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
|
||||||
<hibernate-mapping auto-import="true">
|
<hibernate-mapping auto-import="true">
|
||||||
|
|
||||||
<class name="de.ctdo.bunti.model.Room" table="rooms" >
|
<!--<class name="de.ctdo.bunti.model.Room" table="rooms" >-->
|
||||||
<id name="id" unsaved-value="0">
|
<!--<id name="id" unsaved-value="0">-->
|
||||||
<generator class="native"/>
|
<!--<generator class="native"/>-->
|
||||||
</id>
|
<!--</id>-->
|
||||||
<property name="name"/>
|
<!--<property name="name" column="roomName"/>-->
|
||||||
</class>
|
<!--</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>
|
</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