Skip to content

Commit 536e6c6

Browse files
committed
hibernate introduced
1 parent 6931c78 commit 536e6c6

File tree

8 files changed

+54
-3
lines changed

8 files changed

+54
-3
lines changed

config/log4j.xml

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
<appender-ref ref="request"/>
2828
</logger>
2929

30+
<logger name="org.hibernate.SQL">
31+
<level value="DEBUG"/>
32+
</logger>
33+
3034
<root>
3135
<level value="INFO"/>
3236
<appender-ref ref="general-console"/>

ivy.xml

+4
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@
1717
<dependency org="com.h2database" name="h2" rev="1.3+"/>
1818
<dependency org="commons-dbcp" name="commons-dbcp" rev="1.4"/>
1919
<dependency org="org.liquibase" name="liquibase-core" rev="2.0+"/>
20+
<dependency org="org.hibernate" name="hibernate-core" rev="3.6+"/>
21+
<dependency org="javassist" name="javassist" rev="3.3"/>
2022

2123
<dependency org="org.springframework" name="spring-beans" rev="3.0+"/>
2224
<dependency org="org.springframework" name="spring-web" rev="3.0+"/>
25+
<dependency org="org.springframework" name="spring-jdbc" rev="3.0+"/>
26+
<dependency org="org.springframework" name="spring-orm" rev="3.0+"/>
2327

2428
<dependency org="com.sun.jersey" name="jersey-core" rev="1.8"/>
2529
<dependency org="com.sun.jersey" name="jersey-server" rev="1.8"/>

src/ee/devclub/model/Location.java

+2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package ee.devclub.model;
22

3+
import javax.persistence.Embeddable;
34
import java.io.Serializable;
45

6+
@Embeddable
57
public class Location implements Serializable {
68
private float latitude;
79
private float longitude;

src/ee/devclub/model/PhotoSpot.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
package ee.devclub.model;
22

3+
import javax.persistence.*;
4+
5+
@Entity @Access(AccessType.FIELD)
36
public class PhotoSpot {
4-
Long id;
7+
@GeneratedValue(strategy = GenerationType.IDENTITY)
8+
@Id Long id;
9+
510
String name;
611
String description;
712
Location location;
813

14+
PhotoSpot() {
15+
}
16+
917
public PhotoSpot(String name, String description, Location location) {
1018
this.name = name;
19+
this.description = description;
1120
this.location = location;
1221
}
1322

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package ee.devclub.model;
22

3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.orm.hibernate3.HibernateOperations;
35
import org.springframework.stereotype.Service;
46

57
import java.util.List;
@@ -8,11 +10,14 @@
810

911
@Service
1012
public class PhotoSpotService {
13+
@Autowired HibernateOperations hibernate;
14+
1115
public List<PhotoSpot> getAllSpots() {
12-
return asList(new PhotoSpot("Kohtuotsa vaateplatvorm", "", new Location(59.437755f, 24.74209f)));
16+
return hibernate.loadAll(PhotoSpot.class);
1317
}
1418

1519
public PhotoSpot persist(PhotoSpot spot) {
20+
hibernate.saveOrUpdate(spot);
1621
return spot;
1722
}
1823
}

webapp/WEB-INF/jetty-web.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<Set name="url">jdbc:h2:~/.devclub-java/db;AUTO_SERVER=TRUE;USER=devclub;PASSWORD=devclub</Set>
1212
<Set name="maxActive">5</Set>
1313
<Set name="maxIdle">5</Set>
14-
<Set name="defaultAutoCommit">false</Set>
14+
<Set name="defaultAutoCommit">true</Set>
1515
</New>
1616
</Arg>
1717
</New>

webapp/WEB-INF/liquibase.xml

+13
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,17 @@
1212
</createTable>
1313
</changeSet>
1414

15+
<changeSet id="20110823-1" author="Codeborne">
16+
<renameColumn tableName="PhotoSpot" oldColumnName="lat" newColumnName="latitude"/>
17+
<renameColumn tableName="PhotoSpot" oldColumnName="lon" newColumnName="longitude"/>
18+
</changeSet>
19+
20+
<changeSet id="20110823-2" author="Codeborne">
21+
<insert tableName="PhotoSpot">
22+
<column name="name" value="Kohtuotsa vaateplatvorm"/>
23+
<column name="latitude" value="59.437755"/>
24+
<column name="longitude" value="24.74209"/>
25+
</insert>
26+
</changeSet>
27+
1528
</databaseChangeLog>

webapp/WEB-INF/spring.xml

+14
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,18 @@
1717
<property name="contexts" value="test, production"/>
1818
</bean>
1919

20+
<bean id="hibernateSessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" depends-on="liquibase">
21+
<property name="dataSource" ref="dataSource"/>
22+
<property name="annotatedClasses">
23+
<list>
24+
<value>ee.devclub.model.PhotoSpot</value>
25+
</list>
26+
</property>
27+
</bean>
28+
29+
<bean id="hibernate" class="org.springframework.orm.hibernate3.HibernateTemplate">
30+
<property name="sessionFactory" ref="hibernateSessionFactory"/>
31+
<property name="flushModeName" value="FLUSH_EAGER"/>
32+
</bean>
33+
2034
</beans>

0 commit comments

Comments
 (0)