how to delete row in spring boot - java

I write this in my JpaRepository
#Modifying
#Query("DELETE FROM Backlog b WHERE b.code = ?1")
void deleteBacklog(String code);
and this is my method :
#Transactional
#Override
public Integer deleteBacklog(String code) {
try {
backlogRepository.deleteBacklog(code);
return IReturnedValues.DELETE_BACKLOG_SUCCESS;
}catch(Exception e){
return Integer.MAX_VALUE;
}
}
I got this in the console:
Hibernate: delete from backlog where code=?
but when I check my database I still have the row.
How i call my method:
if(code == null || code == "") {
//user exist, check if the code is valid or not
response=ResponseEntity.ok(IReturnedValues.DELETE_BACKLOG_TOKEN_VALIDE);
}else {
//check if exist a backlog with this code
List<Backlog> backlog = backlogMetier.findByCode(code);
if(backlog == null) {
response= ResponseEntity.ok(IReturnedValues.DELETE_BACKLOG_CODE_NOT_EXISTE);
}else if(backlog != null){
try {
//delete the backlog
retour=backlogMetier.deleteBacklog(code);
response= ResponseEntity.ok(retour);
} catch (Exception e) {
return ResponseEntity.ok(responseClassMax);
}
}
}
this is my entity:
#Entity
public class Backlog {
#Id #GeneratedValue
private Long idBacklog;
private String code;
#ManyToOne(fetch=FetchType.LAZY)
private Utilisateur userBacklog;
private Date creationDate;
private String title;
//getters & setters
//constructors
}
And thanks in advance.

#Query(value=""DELETE FROM Backlog b WHERE b.code = :code")
void deleteBacklog(#Param("code") String code);
It seems Query error, try above code.

use this code
#Repository
public interface BookRepository extends CrudRepository<Book, Long> {
long deleteByTitle(String title);
}
test this method
#Test
#Transactional
public void whenDeleteFromDerivedQuery_thenDeletingShouldBeSuccessful() {
long deletedRecords = repository.deleteByTitle("The Hobbit");
assertThat(deletedRecords).isEqualTo(1);
}

Related

Hibernate: Insert of Update with EntityManager

I have a table with unique constraint on the one field and I want to setup Hibernate EntityManager so it would insert new record only if there is no such record already and will update otherways.
My POJO for the table looks looks this:
#Entity
#Table(name = "links", uniqueConstraints = {
#UniqueConstraint(columnNames = "link", name = "uk_link")
})
public class Link {
private long linkId;
private String link;
private String data;
private String metadata;
private List<Result> results;
#Id
#Column(name="link_id")
#GeneratedValue(strategy=GenerationType.IDENTITY)
public long getLinkId() {
return linkId;
}
public void setLinkId(long linkId) {
this.linkId = linkId;
}
public String getLink() {
return link;
}
public void setLink(String link) {
this.link = link;
}
public String getData() {
return data;
}
public void setData(String data) {
this.data = data;
}
public String getMetadata() {
return metadata;
}
public void setMetadata(String metadata) {
this.metadata = metadata;
}
#OneToMany(cascade=CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "link")
public List<Result> getResults() {
return results;
}
public void setResults(List<Result> results) {
this.results = results;
}
#Override
public String toString() {
return "Link [linkId=" + linkId + ", link=" + link + ", data=" + data + ", metadata=" + metadata + "]";
}
public boolean isDataEquals(String data) {
if (this.data == null) {
if (data != null)
return false;
} else if (!this.data.equals(data))
return false;
return true;
}
public boolean isMetadataEquals(String metadata) {
if (this.metadata == null) {
if (metadata != null)
return false;
} else if (!this.metadata.equals(metadata))
return false;
return true;
}
}
And I'm try to resolve the necessary changes through this code:
public Link selectByLink(String link) {
return entityManager
.createQuery("select l from Link l WHERE l.link = :link", Link.class)
.setParameter("link", link)
.getSingleResult();
}
public void insert(Link link) {
this.entityManager.persist(link);
}
public Link update(Link link) {
return this.entityManager.merge(link);
}
public void save(Link link) {
if (link.getLinkId() == 0) {
Link _existing = selectByLink(link.getLink());
if (null != _existing) {
link.setLinkId(_existing.getLinkId());
if (!_existing.isDataEquals(link.getData()) ||
!_existing.isMetadataEquals(link.getMetadata())) {
update(link);
}
} else
insert(link);
}
}
In the Spring log, I see one additional select:
Hibernate: select link0_.link_id as link_id1_0_, link0_.data as data2_0_, link0_.link as link3_0_, link0_.metadata as metadata4_0_ from links link0_ where link0_.link=?
Hibernate: select link0_.link_id as link_id1_0_1_, link0_.data as data2_0_1_, link0_.link as link3_0_1_, link0_.metadata as metadata4_0_1_, results1_.link_id as link_id1_1_3_, results1_.text_id as text_id2_1_3_, results1_.link_id as link_id1_1_0_, results1_.text_id as text_id2_1_0_, results1_.found as found3_1_0_, results1_.level as level4_1_0_ from links link0_ left outer join results results1_ on link0_.link_id=results1_.link_id where link0_.link_id=?
Hibernate: update links set data=?, link=?, metadata=? where link_id=?
I guess, it happens because I use merge function, but if I do not search for the object id prior merging it, the merge will try to insert object instead of updating it. Is there a way to just update the object without testing it first?
And unrelated question, the SQL's looks very messy. all these link0_.link_id as link_id1_0_, can they be suppressed?
The extra join comes as a result of your lazy one to many relationship. Apart from the select for the link itself, an extra select statement is performed to load the collection (that's the root of the famous N+1 problem).
And, for the selection performed before updating, it seems to be the way hibernate persists by default, when entities are detached. If you want to avoid it you should play with its configuration (there's a select-before-update property) or write an update query yourself. You could as well try to avoid Spring detaching Hibernate entities.

How to set true or false if there is no record in table using hibernate

I am using Spring REST with Hibernate and i am fetching a particular record from database table passing id into my method. The method is working properly but if there is no record in table then i want false in a variable and if record exist then i want true in the variable in my json object.
Here is my Entity class Subscribe.java
#Entity
#Table(name="subscribe")
#JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
public class Subscribe implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue
#Column(name="id")
private long id;
#Column(name="subscribed_id")
private String subID;
#Column(name="subscriber_id")
private long subrID;
public long getSubrID() {
return subrID;
}
public void setSubrID(long subrID) {
this.subrID = subrID;
}
public String getSubID() {
return subID;
}
public void setSubID(String subID) {
this.subID = subID;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
}
Here is my DAO class
#SuppressWarnings({ "unchecked", "rawtypes" })
public List<Subscribe> getSubscribeById(long id) throws Exception {
session = sessionFactory.openSession();
Criteria cr = session.createCriteria(Subscribe.class);
cr.add(Restrictions.eq("subrID", id));
List results = cr.list();
tx = session.getTransaction();
session.beginTransaction();
tx.commit();
return results;
}
And here is my Controller
#RequestMapping(value = "/subscribe/{id}", method = RequestMethod.GET)
public #ResponseBody
List<Subscribe> getSubscriber(#PathVariable("id") long id) {
List<Subscribe> sub = null;
try {
sub = profileService.getSubscribeById(id);
} catch (Exception e) {
e.printStackTrace();
}
return sub;
}
Please suggest me how can can i do this
Given the way your code is structured ( where you effectively pass the database object directly to the REST client ) there is no clean way that you can do this.
I think a more RESTful approach would be to return an HTTP code that indicates that the requested record could not be found. HTTP 404 would be the appropriate code to use.
So, in pseudo-code,
#RequestMapping(value = "/subscribe/{id}", method = RequestMethod.GET)
public #ResponseBody
List<Subscribe> getSubscriber(#PathVariable("id") long id) {
List<Subscribe> sub = null;
try {
sub = profileService.getSubscribeById(id);
} catch (Exception e) {
e.printStackTrace();
}
if ( sub.isEmpty() ){
return HTTP 404 result code
} else {
return sub;
}
}
Your client side code will need to be altered to respond to the HTTP result code rather than a boolean value, but otherwise would remain unchanged.

When I select a row in MySQL using hibernate classes, it makes an update automatically

I'm trying to develop a blacklist for my users including several variables. So when a user sign up in my application, I check if some parameters are blacklisted or not.
The problem is that when I perform a select and the database find something that fits with my search, it automatically perform an update an clean that row.
This is the MySQL log:
86 Query select * from blacklist where mobile_token = 'b'
86 Query SHOW WARNINGS
86 Query select ##session.tx_read_only
86 Query update mydatabase.blacklist set email=null, iban=null, mobile_token=null, nif=null where blacklist_id=1
86 Query SHOW WARNINGS
86 Query commit
86 Query SET autocommit=1
86 Query SET autocommit=1
86 Query set session transaction read write
This is my table:
My model:
package models.classes_hibernate;
import javax.persistence.*;
import static javax.persistence.GenerationType.IDENTITY;
#Entity
#Table(name="blacklist"
,catalog="mydatabase"
)
public class Blacklist implements java.io.Serializable {
private Integer blacklistId;
private String mobileToken;
private String iban;
private String nif;
private String email;
public Blacklist() {
}
#Id #GeneratedValue(strategy=IDENTITY)
#Column(name="blacklist_id", unique=true, nullable=false)
public Integer getBlacklistId() {
return this.blacklistId;
}
public void setBlacklistId(Integer blacklistId) {
this.blacklistId = blacklistId;
}
#Column(name="mobile_token", nullable = false)
public String getMobileToken() {
return this.mobileToken;
}
public void setMobileToken(String name) {
this.mobileToken = mobileToken;
}
#Column(name="iban", nullable = false)
public String getIban() {
return this.iban;
}
public void setIban(String name) {
this.iban = iban;
}
#Column(name="nif", nullable = false)
public String getNif() {
return this.nif;
}
public void setNif(String name) {
this.nif = nif;
}
#Column(name="email", nullable = false)
public String getEmail() {
return this.email;
}
public void setEmail(String name) {
this.email = email;
}
}
And my DAO:
package models.dao;
import com.google.common.collect.Lists;
import models.classes_hibernate.Blacklist;
import models.pages.Page;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.hibernate.type.StringType;
import play.Logger;
import play.db.jpa.JPA;
import play.db.jpa.Transactional;
import javax.persistence.NoResultException;
import javax.persistence.Query;
import java.util.List;
public class BlacklistDAOImpl implements MyAppCRUDDAOInterface<Blacklist> {
#Override
public void create(Blacklist entity) {
JPA.em().persist(entity);
}
#Override
public Blacklist read(Integer id) {
return JPA.em().find(Blacklist.class, id);
}
public Page<Blacklist> readAll(String orientation,int pageSize, int beginElementId)
{
Query query = null;
List<Blacklist> blacklists = null;
boolean areThereMore = false;
Page<Blacklist> allBlacklists = null;
int size = 0;
if(orientation.equals("all")) {
query = JPA.em().createNativeQuery("select * from blacklist",Blacklist.class);
}
if(orientation.equals("lt")) {
query = JPA.em().createNativeQuery("select * from blacklist where blacklist_id < ? ORDER BY blacklist_id DESC",Blacklist.class);
query.setParameter(1, beginElementId);
size =query.getResultList().size();
query.setMaxResults(pageSize);
}
if(orientation.equals("gt")) {
query = JPA.em().createNativeQuery("select * from blacklist blacklist_id > ? ORDER BY blacklist_id ASC",Blacklist.class);
query.setParameter(1, beginElementId);
size =query.getResultList().size();
query.setMaxResults(pageSize);
}
if (size>pageSize)
areThereMore = true;
try {
blacklists = query.getResultList();
if (orientation.equals("gt")) {
List<Blacklist> reverseList = Lists.reverse(blacklists);
blacklists = reverseList;
}
allBlacklists = new Page<Blacklist>(blacklists, areThereMore, "Blacklist");
return allBlacklists;
}
catch(NoResultException nre){
allBlacklists=null;
return allBlacklists;
}
}
#Override
public void update(Blacklist entity) {
JPA.em().merge(entity);
}
#Override
public void delete(Blacklist entity) {
JPA.em().remove(entity);
}
#Override
public boolean isManaged(Blacklist entity) {
return JPA.em().contains(entity);
}
#Override
public void close() {
JPA.em().close();
}
public Boolean isMobileTokenBlacklisted(String mobileToken) {
Query query = JPA.em().createNativeQuery("select * from blacklist where mobile_token = ?",Blacklist.class);
query.setParameter(1, mobileToken);
Blacklist blacklist;
try {
Logger.debug("Voy a comprobar");
blacklist = (Blacklist)query.getSingleResult();
} catch (NoResultException nre){
blacklist=null;
}
return blacklist != null;
}
isMobileTokenBlacklisted call:
#POST
#Path("/api/user")
#ApiOperation(position = 3, nickname ="user", value = "Sign up new user",notes = "Minimum JSON required: ",
response = AppUserJSON.class, httpMethod = "POST")
#BodyParser.Of(BodyParser.Json.class)
#Transactional
public static Result signup() {
AppUserDAOImpl appUserDAO = new AppUserDAOImpl();
AppUserJSON user = null;
AppUser appUser = null;
BlacklistDAOImpl blacklistDAO = new BlacklistDAOImpl();
try {
user = parse();
String encrypt_nif = user.nif;
String encrypt_authorization = user.parental_authorization;
String encrypt_password = user.password;
try {
encrypt_password= EncryptUtils.encrypt(config1.getString("key"),user.password);
if(user.nif!= null)
encrypt_nif = EncryptUtils.encrypt(config1.getString("key"),user.nif);
if(user.parental_authorization!= null)
encrypt_authorization = EncryptUtils.encrypt(config1.getString("key"),user.parental_authorization);
} catch (Exception e) {
e.printStackTrace();
}
appUser = new AppUser(new Date(), new Date(),user.email.toLowerCase(), encrypt_password, user.mobile_token,
user.mobile_device, 0, 0, 0, 0, encrypt_nif,
false,"NOT_LOCKED", encrypt_authorization, 0, false);
if (user.email == null) {
return status (200, "email missing");
} else if (blacklistDAO.isEmailBlacklisted(user.email)){
return status(401, "Email is blacklisted");
}
if (user.password == null)
return status(201, "password missing");
if (user.mobile_token == null) {
return status (206, "mobileToken missing");
} else if (blacklistDAO.isMobileTokenBlacklisted(user.mobile_token)){
Logger.debug("MobileToken blacklisted");
return status(401, "Mobile token is blacklisted");
}
if (user.mobile_device== null)
return status(207, "mobileDevice missing");
else{
appUserDAO.create(appUser);
user.app_user_id= appUser.getAppUserId();
return ok(Json.toJson(user));
}
} catch (IncompleteJSONException e) {
return badRequest("IncompleteJSONException");
} catch (DuplicateJSONException e) {
return badRequest("DuplicateJSONException");
}
}
Thanks!
I don't know where it comes from but we can find a way to correct some thing to improve your code and exclude definitely some queries.
Be sure to use bracket around your if. It's not compulsory but is a way to make the code clearer
In the signup method, the else is not logical. It only depends on the last if (mobiledevice test). You probably want to create your user if all test are wrong.
Here you just want to test if you have any blacklisted element corresponding to your research. You can use COUNT function or even EXISTS which can be more efficient maybe.
You can use Debug mode to see where your update is done too.

#ManyToMany collections in JPA - foreign key constraint fails - (simulate likes and dislikes buttons)

I'm trying to render like/dislike buttons using JPA and JSF
#Entity
public class APost implements Serializable {
...
#ManyToMany(fetch = FetchType.EAGER)
protected Collection<User> likes;
#ManyToMany(fetch = FetchType.EAGER)
protected Collection<User> dislikes;
#Transient
public Integer getLikesNumber() {
if (likes == null) {
return 0;
}
return likes.size();
}
public Collection<User> getLikes() {
return likes;
}
public void setLikes(Collection<User> likes) {
this.likes = likes;
}
public void addLikes(User user) {
if (likes == null) {
likes = new HashSet<>();
}
likes.add(user);
}
public void removeLikes(User user) {
if (likes != null) {
likes.remove(user);
}
}
#Transient
public Integer getDislikesNumber() {
if (dislikes == null) {
return 0;
}
return dislikes.size();
}
public Collection<User> getDislikes() {
return dislikes;
}
public void setDislikes(Collection<User> dislikes) {
this.dislikes = dislikes;
}
public void addDislikes(User user) {
if (dislikes == null) {
dislikes = new HashSet<>();
}
dislikes.add(user);
}
public void removeDislikes(User user) {
if (dislikes != null) {
dislikes.remove(user);
}
}
}
The User Class :
#Entity
public class User implements Serializable {
...
#Id
private String email;
#ManyToMany(fetch = FetchType.EAGER, mappedBy = "likes")
protected Collection<APost> likes;
#ManyToMany(fetch = FetchType.EAGER, mappedBy = "dislikes")
protected Collection<APost> dislikes;
public Collection<APost> getLikes() {
return likes;
}
public void addLikes(APost post) {
if (likes == null) {
likes = new HashSet<>();
}
likes.add(post);
}
public void removeLikes(APost post) {
if (likes != null) {
likes.remove(post);
}
}
public Collection<APost> getDislikes() {
return dislikes;
}
public void addDislikes(APost post) {
if (dislikes == null) {
dislikes = new HashSet<>();
}
dislikes.add(post);
}
public void removeDislikes(APost post) {
if (dislikes != null) {
dislikes.remove(post);
}
}
#Override
public boolean equals(Object obj) {
if (obj == null)
return false;
User uObj = (User) obj;
return getEmail().equals(uObj.getEmail());
}
}
Facelet : post.xhtml
...
<h:commandLink
action="#{bean.addLike(post.id)}"
<h:graphicImage library="images" name="thumb-up-24x31.png"></h:graphicImage>
</h:commandLink>
...
Bean.java
#ManagedBean
#ConversationScoped
public class OnePostManager implements Serializable {
private static final long serialVersionUID = 1L;
#EJB
private IPostFacade postFacade;
#EJB
private IUserFacade userFacade;
#Inject
private LoginManager loginManager;
...
public String addLike(Long postId) {
if (loginManager.getConnected().equals(false)) {
return "login?redirect=post&&faces-redirect=true";
}
if (postId != null) {
APost post = postFacade.find(postId);
User user = userFacade.find(loginManager.getEmail());
post.addLikes(user);
postFacade.edit(post);
}
return null;
}
}
Now, when I click on the "like" button, I got an exception :
javax.faces.el.EvaluationException: javax.ejb.EJBException: Transaction aborted
...
Caused by: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.0.v20130507- 3faac2b): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (`medianovens`.`APOST_USER`, CONSTRAINT `FK_APOST_USER_likes_EMAIL` FOREIGN KEY (`likes_EMAIL`) REFERENCES `USER` (`EMAIL`))
Error Code: 1452
Call: INSERT INTO APOST_USER (dislikes_EMAIL, dislikes_ID) VALUES (?, ?)
bind => [2 parameters bound]
Query: DataModifyQuery(name="dislikes" sql="INSERT INTO APOST_USER (dislikes_EMAIL, dislikes_ID) VALUES (?, ?)")
...
When I look at my database, I've got one table called APOST_USER with 4 columns : dislikes_EMAIL, dislikes_ID, likes_EMAIL, likes_ID
So I suppose that when it tries to add an entry that defines which post a user likes, it tries to fill likes_EMAIL and likes_ID but also expects some values for dislikes_EMAIL and dislikes_ID ...
How can I solve this ?
Note :
When I remove all code concerning dislike functions, the code works OK (My table APOST_USER only has 2 columns, likes_EMAIL and likes_ID) and an entry can be added, but everything goes wrong if I add all code regarding dislike function.
It sounds like your JPA provider is trying to be smart and combine the two references to APost into one. What you should probably do is look into the #JoinTable annotation, which would allow you to definitively specify different tables should be used for your Like and Dislike features.
http://blog.jbaysolutions.com/2012/12/17/jpa-2-relationships-many-to-many/ shows how this is used in practice.
Here's what I think it should look like to fix your mapping problem:
#Entity
public class APost implements Serializable {
...
#JoinTable(name="post_likes")
#ManyToMany(fetch = FetchType.EAGER)
protected Collection<User> likes;
#JoinTable(name="post_dislikes")
#ManyToMany(fetch = FetchType.EAGER)
protected Collection<User> dislikes;
You need to assign both sides of the relationship:
post.addLikes(user);
user.addLikes(post);

Play 2.1-Snapshot: Ebean database updates and deletions don't work in Junit test cases

I have a weird problem. I'm using play 2.1-SNAPSHOT with ebeans (=> mysql). I have a very small (test) setup and for some reason database updates and deletions don't work. Items are created in the DB... but updating them does not work.
Here's my bean (which extends a superclass that adds the timestamps (created and modified date)):
AbstractTimestamp (superclass):
#MappedSuperclass
public abstract class AbstractTimestampedBean extends AbstractIdentifiableBean {
/** The date this item has been created. */
#CreatedTimestamp
public Timestamp createdTime;
}
Project Bean (removed unimportant stuff) - hashCode and equals have been created by eclipse - here we overwrite the methods of play.db.ebean.Model:
#Entity
#Table(name = "Projects")
public class Project extends AbstractTimestampedBean {
private static final long serialVersionUID = -6160140283947231026L;
#NotNull
public String title;
#NotNull
#ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
public User owner;
#NotNull
#ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
public User creator;
#ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
public Set<User> participants;
#EnumMapping(nameValuePairs = "ACTIVE=A,INACTIVE=I,EXPIRED=E")
public enum Status {
ACTIVE, INACTIVE, EXPIRED
}
public Project() {
}
public Project(final String title, final User creator) {
this.title = title;
this.creator = creator;
this.owner = creator;
}
/*
* (non-Javadoc)
*
* #see play.db.ebean.Model#hashCode()
*/
#Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result
+ (this.creator == null ? 0 : this.creator.hashCode());
result = prime * result
+ (this.owner == null ? 0 : this.owner.hashCode());
result = prime * result
+ (this.participants == null ? 0 : this.participants
.hashCode());
result = prime * result
+ (this.title == null ? 0 : this.title.hashCode());
return result;
}
/*
* (non-Javadoc)
*
* #see play.db.ebean.Model#equals(java.lang.Object)
*/
#Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (this.getClass() != obj.getClass()) {
return false;
}
final Project other = (Project) obj;
if (this.creator == null) {
if (other.creator != null) {
return false;
}
} else if (!this.creator.equals(other.creator)) {
return false;
}
if (this.owner == null) {
if (other.owner != null) {
return false;
}
} else if (!this.owner.equals(other.owner)) {
return false;
}
if (this.participants == null) {
if (other.participants != null) {
return false;
}
} else if (!this.participants.equals(other.participants)) {
return false;
}
if (this.title == null) {
if (other.title != null) {
return false;
}
} else if (!this.title.equals(other.title)) {
return false;
}
return true;
}
Here's the very simple test case:
First run creates a projects - checks that it's there (nothing fails here)
Then we update some stuff - store it - and assert again... and here I can see that the db entries have not been updated.
http://pastebin.com/7zdzWGXw
Here's the superclass that we are using here:
public abstract class AbstractPersistableTestCase {
#Transactional
void saveBean(final Model bean) {
Ebean.save(bean);
}
#Transactional
void deleteBean(final Model bean) {
Ebean.delete(bean);
}
#Transactional
<T extends Model> void deleteBeans(final List<T> beans) {
Ebean.delete(beans);
}
}
Error message from jUnit4:
This is the assertion of the title in the update case => See: db entry has not been updated:
[error] Test test.models.ProjectTest.createAndUpdateProject failed: expected:<'Project_[NEW_]1350681993608'> but was:<Project_[]1350681993608'>
This happens when I try to delete the project:
[error] Test test.models.ProjectTest.deleteProjects failed: Data has changed. updated [0] rows sql[delete from user where id=? and name is null and email is null and created_time is null] bind[null]
Do you guys have an idea why this is happening? I'm really frustrated here...
Regards,
Sascha
It seems to me that you are not adding an Id to your classes.
Try to add this to your superclass:
#MappedSuperclass
public abstract class AbstractModel extends play.db.ebean.Model
{
#Id
public Long id;
public Long getId()
{
return id;
}
// ... here your other attributes
}

Categories

Resources