Find the error...JPA ENTITY HIBERNATE

#1
Hey guys....i am searching for some days for the problem...Maybe one of you can find the error

 

DATABASE SHEMA:

https://www.file-upload.net/download-12530779/2017-06-0214_25_00-MySQLWorkbench.png.html

 

 

 

Entities:

 

package com.example.demo;

import java.io.Serializable;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@SuppressWarnings("unused")
@Entity
@Table(name = "user")
public class user implements Serializable {
private static final long serialVersionUID = 1L;
// @GeneratedValue
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
@Column(name = "username")
private String username;
@Column(name = "password")
private String password;
@Column(name = "email")
private String email;

@ManyToMany
@JoinTable(name="chat", joinColumns={@JoinColumn(name="userid1", referencedColumnName="id")}, inverseJoinColumns={@JoinColumn(name="messageid", referencedColumnName="id")})
private Set<message> messages;


public Set<message> getMessages() {
  return messages;
}

public void setMessages(Set<message> messages) {
  this.messages = messages;
}

public int getId() {
  return id;
}

public void setId(int id) {
  this.id = id;
}

public String getUsername() {
  return username;
}

public void setUsername(String username) {
  this.username = username;
}


private String getPassword() {
  return password;
}

public void setPassword(String password) {
  this.password = password;
}

public String getEmail() {
  return email;
}

public void setEmail(String email) {
  this.email = email;
}

public user() {

}

}

 

 

 

 

package com.example.demo;

import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

@Entity
@Table(name = "message")
public class message {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private int id;

@Column(name = "message")
private String message;

@ManyToMany(mappedBy = "messages")
private Set<user> user;

public Set<user> getUser() {
  return user;
}

public void setUser(Set<user> user) {
  this.user = user;
}

public int getId() {
  return id;
}

public void setId(int id) {
  this.id = id;
}

public String getMessage() {
  return message;
}

public void setMessage(String message) {
  this.message = message;
}

public message() {

}
}

 

 

#2

There are two issues with your post:

  1. No description of the error or the issue is provided, just code.
  2. This is the ObjectDB forum. Please use the Hibernate forum for Hibernate specific questions.
ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
#3

 Sry.

the error is that i get in return a endless array with message in users and users in message So my annotations are not right.

 

Another forum? They all to seem to be dead or am i wrong?

 

Thx

 

#4

This is still not the best description of an error (obviously if you get error messages you should include them in your question). Anyway, for Hibernate questions you may try Stack Overflow.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)

Post Reply

To post a reply and/or subscribe to update notifications - please login