Added serializable attribute...
This commit is contained in:
parent
1a1772fabf
commit
9edb9db0cb
5 changed files with 15 additions and 8 deletions
|
@ -35,11 +35,10 @@ public class Main {
|
||||||
user.setName("asd");
|
user.setName("asd");
|
||||||
user.setEmail("test@test.com");
|
user.setEmail("test@test.com");
|
||||||
User user2 = new User();
|
User user2 = new User();
|
||||||
user2.setName("Teszt"); // TODO:
|
user2.setName("Teszt");
|
||||||
// http://www.journaldev.com/3524/spring-hibernate-integration-example-tutorial
|
|
||||||
user2.setEmail("test2@test.com");
|
user2.setEmail("test2@test.com");
|
||||||
user = provider.save(user);
|
// user = provider.save(user);
|
||||||
user2 = provider.save(user2);
|
// user2 = provider.save(user2);
|
||||||
user.getContacts().add(user2);
|
user.getContacts().add(user2);
|
||||||
user2.getContacts().add(user);
|
user2.getContacts().add(user);
|
||||||
LogManager.getLogger().log(Level.DEBUG, "1st's contact: " + user.getContacts().get(0));
|
LogManager.getLogger().log(Level.DEBUG, "1st's contact: " + user.getContacts().get(0));
|
||||||
|
@ -50,7 +49,9 @@ public class Main {
|
||||||
user.getConversations().add(conversation);
|
user.getConversations().add(conversation);
|
||||||
LogManager.getLogger().debug("User: " + user);
|
LogManager.getLogger().debug("User: " + user);
|
||||||
conversation.getUsers().add(user2);
|
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
|
user2.getConversations().add(conversation); // TODO: Fix
|
||||||
// duplicate
|
// duplicate
|
||||||
// key constraint
|
// key constraint
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
package io.github.norbipeti.chat.server.db.domain;
|
package io.github.norbipeti.chat.server.db.domain;
|
||||||
|
|
||||||
public abstract class ChatDatabaseEntity {
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@SuppressWarnings("serial")
|
||||||
|
public abstract class ChatDatabaseEntity implements Serializable {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import javax.persistence.*;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class Conversation extends ChatDatabaseEntity {
|
public class Conversation extends ChatDatabaseEntity {
|
||||||
|
private static final long serialVersionUID = 5058682475353799722L;
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
@Column(name = "id", unique = true, nullable = false)
|
@Column(name = "id", unique = true, nullable = false)
|
||||||
|
|
|
@ -6,11 +6,12 @@ import javax.persistence.*;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class Message extends ChatDatabaseEntity {
|
public class Message extends ChatDatabaseEntity {
|
||||||
|
private static final long serialVersionUID = 6345941601716826570L;
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
@Column(name = "id", unique = true, nullable = false)
|
@Column(name = "id", unique = true, nullable = false)
|
||||||
private Long id;
|
private Long id;
|
||||||
@ManyToOne
|
@ManyToOne(cascade = CascadeType.PERSIST, fetch = FetchType.EAGER)
|
||||||
// @JoinTable(name="user_message")
|
// @JoinTable(name="user_message")
|
||||||
private User sender;
|
private User sender;
|
||||||
private Date time;
|
private Date time;
|
||||||
|
|
|
@ -10,6 +10,7 @@ import javax.persistence.*;
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "\"User\"")
|
@Table(name = "\"User\"")
|
||||||
public class User extends ChatDatabaseEntity {
|
public class User extends ChatDatabaseEntity {
|
||||||
|
private static final long serialVersionUID = 2862762084164225666L;
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
@Column(name = "id", unique = true, nullable = false)
|
@Column(name = "id", unique = true, nullable = false)
|
||||||
|
@ -26,7 +27,7 @@ public class User extends ChatDatabaseEntity {
|
||||||
private String sessionid;
|
private String sessionid;
|
||||||
@ElementCollection(fetch = FetchType.EAGER)
|
@ElementCollection(fetch = FetchType.EAGER)
|
||||||
// @ManyToMany(fetch = FetchType.EAGER, mappedBy = "users")
|
// @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")
|
// @ManyToMany(mappedBy = "users")
|
||||||
// @JoinTable(name = "User_Conversation", joinColumns =
|
// @JoinTable(name = "User_Conversation", joinColumns =
|
||||||
// @JoinColumn(referencedColumnName = "id", unique = false),
|
// @JoinColumn(referencedColumnName = "id", unique = false),
|
||||||
|
|
Loading…
Reference in a new issue