I have problem with using EntityManager.persist(Object)
method. Now when i get rid of other problems, by app work without Exception but object is not put in my data
You will need to assign id generation strategy as below:
@Entity
@Table(name ="Chain")
public class Chain implements Serializable{
@Id
@Column(name = "id")
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id;
@Column(name = "date")
private Date date;
@Column(name = "name")
private String name;
//setters and getters
}
and in save method
public int saveChain(Chain chain) {
chain.setDate(new Date());
//chain.setId((long)44); remove this line
Boolean a;
em.persist(chain);
return 222;
}
if you assign Id, then hibernate/jpa will try to update record, which is not available, instead of inserting new record and I think will not throw exception.