Added serializable attribute...

This commit is contained in:
Norbi Peti 2016-08-01 14:50:03 +02:00
parent 1a1772fabf
commit 9edb9db0cb
5 changed files with 15 additions and 8 deletions

View file

@ -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

View file

@ -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 {
}

View file

@ -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)

View file

@ -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;

View file

@ -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),