Following class fail to load with the Hibernate
package com.project.alice.entities;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import com.fasterxml.jackson.annotation.JsonProperty;
#Table
#Entity
public class AnyInformation<T, K> {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
#JsonProperty("id")
private long id;
#JsonProperty("parent")
#ManyToOne
private T parent;
#ManyToOne
#JsonProperty("parentType")
private K parentType;
#JsonProperty("informationType")
private String informationType;
#JsonProperty("information")
private String information;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public T getParent() {
return parent;
}
public void setParent(T parent) {
this.parent = parent;
}
public K getParentType() {
return parentType;
}
public void setParentType(K parentType) {
this.parentType = parentType;
}
public String getInformationType() {
return informationType;
}
public void setInformationType(String informationType) {
this.informationType = informationType;
}
public String getInformation() {
return information;
}
public void setInformation(String information) {
this.information = information;
}
}
org.hibernate.AnnotationException:
Property com.project.alice.entities.AnyInformation.parent
has an unbound type and no explicit target entity.
Resolve this Generic usage issue or set an explicit target attribute
(eg #OneToMany(target=) or use an explicit #Type
Please help me here.
You should try something like -
#ManyToOne(targetEntity=Sample.class)
#JoinColumn(name = "<ID>")
private P parent;
#OneToMany(mappedBy = "parent", cascade = CascadeType.PERSIST, targetEntity=Sample.class)
private List<C> children;
Where, P and C extends Sample Class.
I hope it helps.
Note : As per my knowledge It can't be generic as you are expecting. You can not provide any object as a parameter. But the object should be related to the entity you are defining like Parent or Child. That's how it works in Hibernate.
Related
I'm trying to build an application with Netbean. I use Eclipse IDE & JPA API. the Entities is like this:
NATS.java
#Entity
#Table(name = "NATS")
Public Class NATS implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer code;
private String nName;
#Column(name = "cap_id") // for foreign key purpose
private Integer capId;
#OneToOne(cascade=CascadeType.PERSIST)
#PrimaryKeyJoinColumn(name = "cap_id" )
private City capital;
public City getCapital(){
return this.capital;
}
public void setCapital (City newcapital){
this.capital = newcapital;
}
... some gets & sets methods
}
City.java
#Entity
public class City implements Serializable {
private static final long serialVersionUID = 1L;
private String cityName;
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Basic(optional = false)
private Integer cityId;
public String getCityName() {
return cityName;
}
public void setCityName(String newcityName) {
this.cityName = newcityName;
}
public City(String ctname) {
this.cityName = ctname;
}
public Integer getcityId() {
return cityId;
}
public void setcityId(Integer ctId) {
this.cityId = ctId;
}
}
When i want to add new pair of NATS & City, i use this :
somebean.java
#Stateless
public class somebean {
#PersistenceContext(unitName = "TestLocal")
private EntityManager em;
public NATs insertNewCC(String capitalname, String countryname){
City newcapital = new City(capitalname );
NATS newcountry = new NATS();
newcountry.setNationName(countryname);
newcountry.setCapital(newcapital);
em.persist(newcountry); // both objects persisted well, with "capId" still null
return newcountry;
}
public void updateCapitalId(Nations country){
country.setCapitalId(country.getCapital().getcityId());
em.merge(country);
}
}
Here is the service:
genericResource.java
#Path("generic")
public class GenericResource {
#Context
private UriInfo context;
#EJB
private somebean r;
#GET
#Path("/inscountry")
#Produces("application/json")
public List<NATS> insCountry( #QueryParam("countryname") String countryname, #QueryParam("capitalname") String capitalname){
NATS newcountry = r.insertNewCC(capitalname, countryname);
//r.updateCapitalId(newcountry); <-- i want to avoid using this line
List<NATS> result= r.getListNATS();
return result;
}
When i comment the line : r.updateCapitalId(newcountry);
i get a pair of country and capital city with a relation displayed correctly in JSON, but when the session closes. it losses the relation because the foreign key is not saved. the capId in NATs entity is null after persist completed. So i need 1 persist & 1 merge to complete this. is there a better solution beside using that line i commented?
Thank you.
Redesign your entity NATS like this :
package com;
import java.io.Serializable;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
#Entity
#Table(name = "NATS")
public class NATS
implements Serializable
{
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private Integer code;
private String name;
// for foreign key purpose
#OneToOne(cascade = CascadeType.PERSIST)
#JoinColumn(name = "cap_id")
private City capital;
public City getCapital()
{
return this.capital;
}
public void setCapital(City newcapital)
{
this.capital = newcapital;
}
public Integer getCode()
{
return this.code;
}
public void setCode(Integer code)
{
this.code = code;
}
public String getName()
{
return this.name;
}
public void setName(String name)
{
this.name = name;
}
}
and then code for execution will remain same :
City newcapital = new City(capitalname);
NATS newcountry = new NATS();
newcountry.setName(countryname);
newcountry.setCapital(newcapital);
this.entityManager.persist(newcountry);
First of all, try to use indents and a formatter because your code is a mess. Second you want to save two entities (NATS and Country) so you must to uncomment the line where you update the city or persist one by one. If you are starting a new application I recommend you to use Spring boot and it's SpringRepository Interface to make those kind of things easier and clear.
Entity-relationship diagram:
I want to receive a translation, but the element will link back to translation.
So it will crash because it keeps looping..
Translation entity:
package com.exstodigital.photofactory.model;
import javax.persistence.*;
import java.io.Serializable;
/**
* Created by youri on 21-09-16.
*/
#Table(name = "translation")
#Entity
public class Translation implements Serializable {
#Id
#GeneratedValue
private int id;
public int getId() {
return id;
}
private String text;
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
#OneToOne
#JoinColumn(name = "language_id")
private Language language;
public Language getLanguage() {
return language;
}
#OneToOne
#JoinColumn(name = "element_id")
private Element element;
public Element getElement() {
return element;
}
public Translation(int id, String text) {
this.id = id;
this.text = text;
}
public Translation() {
// Empty constructor
}
#Override
public boolean equals(Object obj) {
return obj instanceof Translation && (!this.text.equals(((Translation) obj).text));
}
}
Element entity:
package com.exstodigital.photofactory.model;
import javax.persistence.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* Created by youri on 21-09-16.
*/
#Entity
#Table(name = "element")
public class Element implements Serializable {
#Id
#GeneratedValue
private int id;
public int getId() {
return id;
}
private String label;
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
#OneToMany
#JoinColumn(name = "element_id")
private List<Translation> translations = new ArrayList<>();
public List<Translation> getTranslations() {
return Collections.unmodifiableList(translations);
}
public Element(int id, String label) {
this.id = id;
this.label = label;
}
public Element() {
// Empty constructor
}
#Override
public boolean equals(Object obj) {
return obj instanceof Element && (this.id != ((Element) obj).id || !this.label.equals(((Element) obj).label));
}
}
TranslationDaoImpl:
#Override
public Translation get(int id) {
return sessionFactory.openSession().get(Translation.class, id);
}
You have established wrong relationship, from one side you are giving OneToOne and with same but from second entity you are giving OneToMany
Your code:
#Table(name = "translation")
#Entity
public class Translation implements Serializable {
#OneToOne
#JoinColumn(name = "element_id")
private Element element;
}
#Entity
#Table(name = "element")
public class Element implements Serializable {
#OneToMany
#JoinColumn(name = "element_id")
private List<Translation> translations = new ArrayList<>();
}
Right code for OneToOne :
#Table(name = "translation")
#Entity
public class Translation implements Serializable {
#JsonIgnore
#OneToOne
#JoinColumn(name = "element_id")
private Element element;
}
#Entity
#Table(name = "element")
public class Element implements Serializable {
#OneToOne
(mappedBy="element")
private Translation translation;
}
Right code for OneToMany :
#Table(name = "translation")
#Entity
public class Translation implements Serializable {
#JsonIgnore
#ManyToOne
#JoinColumn(name = "element_id")
private Element element;
}
#Entity
#Table(name = "element")
public class Element implements Serializable {
#OneToMany
(mappedBy="element")
private List<Translation> translations;
}
Use "#JsonIgnore" to avoid Infinite recursion that is coming into your
code
When trying to serialize a Category I get a stackoverflow.
Exception
Warning: StandardWrapperValve[dispatcher]: Servlet.service() for
servlet dispatcher threw exception java.lang.StackOverflowError at
java.lang.ClassLoader.defineClass1(Native Method) at
java.lang.ClassLoader.defineClass(ClassLoader.java:760) at
org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.findClass(BundleWiringImpl.java:2279)
at
org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1501)
at
org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:75)
at
org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1955)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at
com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:660)
at
com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:152)
at
com.fasterxml.jackson.databind.ser.impl.IndexedListSerializer.serializeContents(IndexedListSerializer.java:100)
at
com.fasterxml.jackson.databind.ser.impl.IndexedListSerializer.serializeContents(IndexedListSerializer.java:21)
at
com.fasterxml.jackson.databind.ser.std.AsArraySerializerBase.serialize(AsArraySerializerBase.java:183)
at
com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:541)
at
com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:644)
at
com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:152)
Category.java
#Entity
public class Category implements DataObject, Serializable {
#Id
#GeneratedValue
private Long id;
private String title;
private String description;
#ManyToOne #JsonIgnore
private Category parent;
#Override
public long getId() {
return id;
}
#Override
public void setId(long id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Category getParent() {
return null;//return parent;
}
public void setParent(Category parent) {
// this.parent = parent;
}
public boolean isMainCategory()
{
return true;// return this.parent == null;
}
/**
* Returns the chain of parent categories with the main category on index 0
* #return Chain of categories
*/
public List<Category> getParentChain()
{
List<Category> cats = new ArrayList<>();
Category current = this;
while(!current.isMainCategory())
{
cats.add(current);
current = current.getParent();
}
cats.add(current);
Collections.reverse(cats);
return cats;
}
#Override
public String toString()
{
return this.title;
}
#Override
public boolean equals(Object o)
{
if(!(o instanceof Category))return false;
Category c = (Category)o;
return c.title.equals(this.title);
}
#Override
public int hashCode()
{
return super.hashCode();
}
}
Rest Controller function
#RequestMapping(value="/{id}", method=RequestMethod.GET)
public ResponseEntity<Category> get(#PathVariable("id") long categoryId)
{
Category c = service.getCategoryRepository().ReadValue(categoryId);
if(c == null)
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
return new ResponseEntity<>(c,HttpStatus.OK);
}
Note
Even when I replace return new ResponseEntity<>(c,HttpStatus.OK); with return new ResponseEntity<>(new Category(),HttpStatus.OK); I will get a stackoverflow whilist none of the fields contain a value.
It works fine with my other classes it's only this class that causes a stackoverflow.
Sure thing, #JsonIgnore does the job. But what if we need ignored field in our JSON output?
The solution is very simple.
We annotate our 'guilty' field by #JsonManagedReference annotation on the one side of our relation (which means our #ManyToMany annotation).
And #JsonBackReference on the other side of relation (where #OneToMany has been placed).
And that's it. No more recursive loops.
Probably if you comment private Category parent; you will not have the StackOverflow. I've got the same problem in a project with circular dependencies.
The best way to solve this problem is to use the id of the parent instead of the Class like:
private Long parentId;
Edit:
The problem is with getParentChain() that is trying to be serialized. By adding #JsonIgnore before the method the problem was resolved.
One annotation solves your problem.
Add following annotation on class.
#JsonIdentityInfo(
generator = ObjectIdGenerators.PropertyGenerator.class,
property = "id")
Other way is to annotate on Collections #JsonManagedReference for forward direction and #JsonBackReference. for backward direction in mapping.
example:
public class User{
#JsonManagedReference
#OneToMany(mappedBy = "user")
Set<Address> s = new Hashset<>();
}
public class Address{
#JsonBackReference
#ManyToOne
#JoinColumn
User user;
}
This is what i do to avoid this recursive hell.
Add #JsonIgnore to every single #OneToMany(mappedBy="xxxx") in your JPA Entities
JsonIgnore is from jackson-annotations
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-annotations -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.10.0</version>
</dependency>
JPA Entity example:
package model;
import java.io.Serializable;
import javax.persistence.*;
import javax.xml.bind.annotation.XmlRootElement;
import com.fasterxml.jackson.annotation.JsonIgnore;
import java.util.List;
/**
* The persistent class for the categoria database table.
*
*/
#Entity
#NamedQuery(name="Categoria.findAll", query="SELECT c FROM Categoria c")
#XmlRootElement(name = "categoria")
public class Categoria implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#Column(name="categoria_id")
private int categoriaId;
private String descripcion;
#JsonIgnore
//bi-directional many-to-one association to Establecimiento
#OneToMany(mappedBy="categoria")
private List<Establecimiento> establecimientos;
public Categoria() {
}
public int getCategoriaId() {
return this.categoriaId;
}
public void setCategoriaId(int categoriaId) {
this.categoriaId = categoriaId;
}
public String getDescripcion() {
return this.descripcion;
}
public void setDescripcion(String descripcion) {
this.descripcion = descripcion;
}
public List<Establecimiento> getEstablecimientos() {
return this.establecimientos;
}
public void setEstablecimientos(List<Establecimiento> establecimientos) {
this.establecimientos = establecimientos;
}
public Establecimiento addEstablecimiento(Establecimiento establecimiento) {
getEstablecimientos().add(establecimiento);
establecimiento.setCategoria(this);
return establecimiento;
}
public Establecimiento removeEstablecimiento(Establecimiento establecimiento) {
getEstablecimientos().remove(establecimiento);
establecimiento.setCategoria(null);
return establecimiento;
}
}
I have class Menu, it's a self to self with manytoone and onetomany relational.
package models;
import java.util.*;
import javax.persistence.*;
import play.db.ebean.*;
import play.data.format.*;
import play.data.validation.*;
import static play.data.validation.Constraints.*;
import javax.validation.*;
import org.codehaus.jackson.annotate.JsonBackReference;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.annotate.JsonManagedReference;
import com.avaje.ebean.*;
import play.i18n.Messages;
#Entity
public class Menu extends Model {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
public Long id;
#Required
#MinLength(4)
#MaxLength(30)
public String name;
public String url;
#Transient
public boolean hasChild() {
return url.isEmpty();
}
public Integer idx;
#Temporal(TemporalType.TIMESTAMP)
#Formats.DateTime(pattern = "yyyy/MM/dd hh:mm:ss")
public Date created;
#Required
public boolean enabled;
#ManyToOne
#JsonBackReference
public Menu parent;
#OneToMany
#JsonManagedReference("parent")
public List<Menu> children;
public static Model.Finder<Long, Menu> find = new Model.Finder<Long, Menu>(Long.class, Menu.class);
public static List<Menu> findTops() {
return find.where().eq("parent_id", null).eq("enabled", true).orderBy("idx asc").findList();
}
public static List<Menu> findChildsByParent(Menu parent) {
return findChildsByParent(parent, true);
}
public static List<Menu> findChildsByParent(Menu parent, boolean enabled) {
return find.where().eq("parent_id", parent.id).eq("enabled", enabled).orderBy("idx asc").findList();
}
public static boolean hasChilds(Menu parent) {
return hasChilds(parent, true);
}
public static boolean hasChilds(Menu parent, boolean enabled) {
return find.where().eq("parent_id", parent.id).eq("enabled", enabled).findList().size() > 0;
}
public static Page<Menu> findPage(int page, int size) {
return find.findPagingList(size).getPage(page - 1);
}
public Menu() {
}
}
In Controller code is :
#BodyParser.Of(BodyParser.Json.class)
public static Result menuJson() {
if (menus == null) {
menus = Menu.find.all();
}
JsonNode json = new ObjectMapper().valueToTree(menus);
return ok(json);
}
Error details is:
[RuntimeException: java.lang.IllegalArgumentException: Query threw SQLException:Unknown column 't1.menu_id' in 'on clause' Bind values:[1] Query was: select t0.id c0 , t1.id c1, t1.name c2, t1.url c3, t1.idx c4, t1.created c5, t1.enabled c6, t1.parent_id c7 from menu t0 left outer join menu t1 on t1.menu_id = t0.id where t0.id = ? order by t0.id (through reference chain: com.avaje.ebean.common.BeanList[0]->models.Menu["children"])]
It's there have good solution to solve them or how to declare a custom serialize? For the tree model i don't have good object to class design,is't there a better design for this env.?
I solve them.
Add a mapped on OneToMany is works.
package models;
import java.util.*;
import javax.persistence.*;
import play.db.ebean.*;
import play.data.format.*;
import play.data.validation.*;
import static play.data.validation.Constraints.*;
import javax.validation.*;
import org.codehaus.jackson.annotate.JsonBackReference;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.annotate.JsonManagedReference;
import com.avaje.ebean.*;
import play.i18n.Messages;
#Entity
public class Menu extends Model {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
public Long id;
#Required
#MinLength(4)
#MaxLength(30)
public String name;
public String url;
#Transient
public boolean hasChild() {
return url.isEmpty();
}
public Integer idx;
#Temporal(TemporalType.TIMESTAMP)
#Formats.DateTime(pattern = "yyyy/MM/dd hh:mm:ss")
public Date created;
#Required
public boolean enabled;
#ManyToOne
#JsonBackReference
public Menu parent;
#OneToMany(mappedBy = "parent", cascade = CascadeType.PERSIST)
#JsonManagedReference
public List<Menu> children;
public static Model.Finder<Long, Menu> find = new Model.Finder<Long, Menu>(Long.class, Menu.class);
public static List<Menu> findTops() {
return find.where().eq("parent_id", null).eq("enabled", true).orderBy("idx asc").findList();
}
public static List<Menu> findChildsByParent(Menu parent) {
return findChildsByParent(parent, true);
}
public static List<Menu> findChildsByParent(Menu parent, boolean enabled) {
return find.where().eq("parent_id", parent.id).eq("enabled", enabled).orderBy("idx asc").findList();
}
public static boolean hasChilds(Menu parent) {
return hasChilds(parent, true);
}
public static boolean hasChilds(Menu parent, boolean enabled) {
return find.where().eq("parent_id", parent.id).eq("enabled", enabled).findList().size() > 0;
}
public static Page<Menu> findPage(int page, int size) {
return find.findPagingList(size).getPage(page - 1);
}
public Menu() {
}
}
I'm using JPA (Hibernate implementation) to save objects to the database. Selecting works fine, but for some reason, saving doesn't work. I don't get any errors, but the database doesn't get changed either. This goes for both new entities and existing ones.
EPayment pay = new EPayment();
pay.setAmount(payment.getAmount());
...
pay.setUserByToUserId(receiver);
CompayDAO.get().save(pay);
CompayDAO.save()
public void save(Object ent) {
System.out.println("Persisting: " + ent + " using " + this);
this.em.persist(ent);
}
Console output:
Opening DOA nl.compay.entities.CompayDAO#b124fa
Persisting: nl.compay.entities.EUser#1e2fe5d using nl.compay.entities.CompayDAO#b124fa
Persisting: nl.compay.entities.EUser#30b601 using nl.compay.entities.CompayDAO#b124fa
Persisting: nl.compay.entities.EPayment#ed3b53 using nl.compay.entities.CompayDAO#b124fa
Closing DOA nl.compay.entities.CompayDAO#b124fa
EPayment
package nl.compay.entities;
// Generated 21-mei-2009 12:27:07 by Hibernate Tools 3.2.2.GA
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
/**
* Payment generated by hbm2java
*/
#Entity
#Table(name = "payment", catalog = "compay")
public class EPayment implements java.io.Serializable {
private static final long serialVersionUID = -2578493336948256566L;
private Integer id;
private EUser userByToUserId;
private EUser userByFromUserId;
private String description;
private float amount;
private String method;
private Date paydate;
public EPayment() {
}
public EPayment(EUser userByToUserId, EUser userByFromUserId, float amount,
Date paydate) {
this.userByToUserId = userByToUserId;
this.userByFromUserId = userByFromUserId;
this.amount = amount;
this.paydate = paydate;
}
public EPayment(EUser userByToUserId, EUser userByFromUserId,
String description, float amount, String method, Date paydate) {
this.userByToUserId = userByToUserId;
this.userByFromUserId = userByFromUserId;
this.description = description;
this.amount = amount;
this.method = method;
this.paydate = paydate;
}
#Id
#GeneratedValue(strategy = IDENTITY)
#Column(name = "id", unique = true, nullable = false)
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
#ManyToOne(fetch = FetchType.LAZY)
#JoinColumn(name = "to_user_id", nullable = false)
public EUser getUserByToUserId() {
return this.userByToUserId;
}
public void setUserByToUserId(EUser userByToUserId) {
this.userByToUserId = userByToUserId;
}
#ManyToOne(fetch = FetchType.LAZY)
#JoinColumn(name = "from_user_id", nullable = false)
public EUser getUserByFromUserId() {
return this.userByFromUserId;
}
public void setUserByFromUserId(EUser userByFromUserId) {
this.userByFromUserId = userByFromUserId;
}
#Column(name = "description", length = 1024)
public String getDescription() {
return this.description;
}
public void setDescription(String description) {
this.description = description;
}
#Column(name = "amount", nullable = false, precision = 8)
public float getAmount() {
return this.amount;
}
public void setAmount(float amount) {
this.amount = amount;
}
#Column(name = "method", length = 50)
public String getMethod() {
return this.method;
}
public void setMethod(String method) {
this.method = method;
}
#Temporal(TemporalType.TIMESTAMP)
#Column(name = "paydate", nullable = false, length = 0)
public Date getPaydate() {
return this.paydate;
}
public void setPaydate(Date paydate) {
this.paydate = paydate;
}
}
As Sherkaner mentioned, a save doesn't result in an INSERT or UPDATE directly. You have to flush the session or - better in my opinion - close the unit of work / commit the transaction. You do have transactions?
use #Transactional on your method.....
#Transactional
public void save(Object ent){
.....
.....
}
The program doesn't have to sync with the database right away, have you tried this.em.flush(); somewhere?
Don't think this as bug in Hibernate implementation.This is desired behavior,you would like to have minimum communication with database so Hibernate(or any good ORM framework) will consolidate all your changes and will flush your changes in one go.