diff --git a/src/io/github/norbipeti/chat/server/Main.java b/src/io/github/norbipeti/chat/server/Main.java index 4fca01c..68ad7c2 100644 --- a/src/io/github/norbipeti/chat/server/Main.java +++ b/src/io/github/norbipeti/chat/server/Main.java @@ -35,11 +35,10 @@ public class Main { user.setName("asd"); user.setEmail("test@test.com"); User user2 = new User(); - user2.setName("Teszt"); // TODO: - // http://www.journaldev.com/3524/spring-hibernate-integration-example-tutorial + user2.setName("Teszt"); user2.setEmail("test2@test.com"); - user = provider.save(user); - user2 = provider.save(user2); + // user = provider.save(user); + // user2 = provider.save(user2); user.getContacts().add(user2); user2.getContacts().add(user); LogManager.getLogger().log(Level.DEBUG, "1st's contact: " + user.getContacts().get(0)); @@ -50,7 +49,9 @@ public class Main { user.getConversations().add(conversation); LogManager.getLogger().debug("User: " + user); conversation.getUsers().add(user2); - LogManager.getLogger().debug("User2: " + user2); + LogManager.getLogger().debug("User2: " + user2); // TODO: Switch + // to JSON + // files? user2.getConversations().add(conversation); // TODO: Fix // duplicate // key constraint diff --git a/src/io/github/norbipeti/chat/server/db/domain/ChatDatabaseEntity.java b/src/io/github/norbipeti/chat/server/db/domain/ChatDatabaseEntity.java index 56af04a..21f0085 100644 --- a/src/io/github/norbipeti/chat/server/db/domain/ChatDatabaseEntity.java +++ b/src/io/github/norbipeti/chat/server/db/domain/ChatDatabaseEntity.java @@ -1,5 +1,8 @@ package io.github.norbipeti.chat.server.db.domain; -public abstract class ChatDatabaseEntity { +import java.io.Serializable; + +@SuppressWarnings("serial") +public abstract class ChatDatabaseEntity implements Serializable { } diff --git a/src/io/github/norbipeti/chat/server/db/domain/Conversation.java b/src/io/github/norbipeti/chat/server/db/domain/Conversation.java index 7c44ab3..1129ccc 100644 --- a/src/io/github/norbipeti/chat/server/db/domain/Conversation.java +++ b/src/io/github/norbipeti/chat/server/db/domain/Conversation.java @@ -9,6 +9,7 @@ import javax.persistence.*; @Entity public class Conversation extends ChatDatabaseEntity { + private static final long serialVersionUID = 5058682475353799722L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id", unique = true, nullable = false) diff --git a/src/io/github/norbipeti/chat/server/db/domain/Message.java b/src/io/github/norbipeti/chat/server/db/domain/Message.java index 84a5650..9d23dde 100644 --- a/src/io/github/norbipeti/chat/server/db/domain/Message.java +++ b/src/io/github/norbipeti/chat/server/db/domain/Message.java @@ -6,11 +6,12 @@ import javax.persistence.*; @Entity public class Message extends ChatDatabaseEntity { + private static final long serialVersionUID = 6345941601716826570L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id", unique = true, nullable = false) private Long id; - @ManyToOne + @ManyToOne(cascade = CascadeType.PERSIST, fetch = FetchType.EAGER) // @JoinTable(name="user_message") private User sender; private Date time; diff --git a/src/io/github/norbipeti/chat/server/db/domain/User.java b/src/io/github/norbipeti/chat/server/db/domain/User.java index 81be3eb..292cc69 100644 --- a/src/io/github/norbipeti/chat/server/db/domain/User.java +++ b/src/io/github/norbipeti/chat/server/db/domain/User.java @@ -10,6 +10,7 @@ import javax.persistence.*; @Entity @Table(name = "\"User\"") public class User extends ChatDatabaseEntity { + private static final long serialVersionUID = 2862762084164225666L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id", unique = true, nullable = false) @@ -26,7 +27,7 @@ public class User extends ChatDatabaseEntity { private String sessionid; @ElementCollection(fetch = FetchType.EAGER) // @ManyToMany(fetch = FetchType.EAGER, mappedBy = "users") - @ManyToMany(mappedBy = "users", fetch = FetchType.EAGER, cascade = CascadeType.ALL) + @ManyToMany(mappedBy = "users", fetch = FetchType.EAGER, cascade = CascadeType.MERGE) // @ManyToMany(mappedBy = "users") // @JoinTable(name = "User_Conversation", joinColumns = // @JoinColumn(referencedColumnName = "id", unique = false),