Can not read embedded objects with JDO on App Engine - java

I have two simple Pojos User and Rating. User has an embedded list of ratings.
The classes are annoted with #PersistenceCapable and the proprties with #Persistent.
I wrote a simple test that creates a User, sets ratings and persists it with
PersistenceManager pm = PMF.get().getPersistenceManager();
pm.makePersistent(user);
When I fetch the object like this ratings is null (not as I expected):
User user = (User) pm.getObjectById(User.class, key);
I tried some things to solve the problem:
When I annote the property ratings in User with #Persistent(defaultFetchGroup = "true") the list contains an object with a key, parentkey etc. but the value is never set (resulting in 0.0 instead of the actual value).
I could solve the problem by additionally setting a transaction before persisting the data:
pm.currentTransaction().begin();
pm.makePersistent(user);
pm.currentTransaction().commit();
So finally it works with the annotation and the transaction. But why is it?
The behaviour is the same in local unit tests (with the test helper), dev mode and deployed on app engine.
I am using App Engine SDK 1.8.1.
For reference here are User, Rating and the test:
#PersistenceCapable
public class User {
#PrimaryKey
#Persistent(valueStrategy=IdGeneratorStrategy.IDENTITY)
private Key key;
// if added ratings is fetched
#Persistent(defaultFetchGroup = "true")
private List<Rating> ratings;
public Key getKey() {
return key;
}
public void setKey(Key key) {
this.key = key;
}
public List<Rating> getRatings() {
return ratings;
}
public void setRatings(List<Rating> ratings) {
this.ratings = ratings;
}
}
#PersistenceCapable
public class Rating {
#PrimaryKey
#Persistent(valueStrategy=IdGeneratorStrategy.IDENTITY)
private Key key;
#Persistent
private double rating;
public Key getKey() {
return key;
}
public void setKey(Key key) {
this.key = key;
}
public double getRating() {
return rating;
}
public void setRating(double rating) {
this.rating = rating;
}
}
#Test
public void testFindByIdWithExistingKey() throws DaoException {
User user = new User();
List<Rating> ratings = new ArrayList<Rating>();
Rating rating = new Rating();
rating.setRating(1.2);
ratings.add(rating);
user.setRatings(ratings);
Key key = persist(user);
User user2 = dao.findById(key);
Assert.assertEquals(1.2, user2.getRatings().get(0).getRating(), 0.0001);
}
private Key persist(User user) {
PersistenceManager pm = PMF.get().getPersistenceManager();
try {
//pm.currentTransaction().begin();
pm.makePersistent(user);
//pm.currentTransaction().commit();
return user.getKey();
} finally {
pm.close();
}
}
#Override
public User findById(Key key) throws DaoException {
PersistenceManager pm = PMF.get().getPersistenceManager();
try {
User user = (User) pm.getObjectById(User.class, key);
return user;
} catch (RuntimeException e) {
throw new DaoException("could not find user", e);
} finally {
pm.close();
}
}

Related

How to get access to a HashMap of objects from the Objects in that HashMap. (Java)

I have a hash map of some POJO Objects of a Class named User: HashMap<ObjectId, User>
These objects (Users) are related to each other. (I need to search through other users to Update one's Parameters)
How can I have access to the HashMap within a user object?
import org.bson.types.ObjectId;
import org.bson.BsonDocument;
import java.util.ArrayList;
import java.util.List;
public class User {
private ObjectId _id;
private int grade;
private String region;
private ArrayList<ObjectId> _reg_by;
private ObjectId regBy;
public User(){
}
public ObjectId getId() {
return _id;
}
public void setId(final ObjectId id) {
this._id = id;
}
public int getGrade() {
return grade;
}
public void setGrade(final int grade) {
this.grade = grade;
}
public String getRegion() {
return region;
}
public void setRegion(final String region) {
this.region = region;
}
public ObjectId getRegBy() {
if(regBy == null) {
regBy = ((_reg_by.size() != 0) ? _reg_by.get(0) : null);
}
return regBy;
}
public void setRegBy(final ObjectId regBy) {
this.regBy = regBy;
}
public ArrayList<ObjectId> get_reg_by(){
return _reg_by;
}
public void set_reg_by(ArrayList<ObjectId> _reg_by){
this._reg_by = _reg_by;
}
private String updateRegion(){
if(getRegBy() == null)
return null;
//TODO search for the person who registered him and use the region!
// how to get access to others from here?!
}
}
This is the User class where in regionUpdate() function I want to have this access
I creat this HashMap in my Main function.
HashMap<ObjectId, User> users = mongoHandler.getUsers();
I solved my problem by defining my HashMap as Static.
public static HashMap<ObjectId, User> users
so I can easily have access to it from anywhere by using the following code:
HashMap<ObjectId, User> users = Main.users
or any method e.g. Main.users.getId();
Another solution could have been to create a property within your "User" class that contains a list of related users, and if you know that one user is related to another, added it to the each user as you build the list.
public class User {
...
private List<User> relatedUsers = new ArrayList<User>();
...
private void updateRelatedUsers() {
for(User relatedUser : relatedUsers) {
//do stuff to update the relatedUser object.
relatedUser.setSomething(someValue);
}
}
//Getter and setter
public List<User> getRelatedUsers() {
return relatedUsers;
}
public void setRelatedUsers(List<User> relatedUsers) {
this.relatedUsers = relatedUsers;
}
...
}
Add the users like so:
...
User myUser = creatUserHoweverYouDo();
User myRelatedUser = getMyRelatedUser(myUser);
myUser.getRelatedUsers().add(myRelatedUser);
...

detached entity passed to persist for batch insert in JPA

For the following batch insert method, i get this exception "detached entity passed to persist". Could you take a look at this method and give me some hints?
Thank you so much.
if needed, I will provided the entities here, for the moment I provide Keyword entity :
public class Keyword implements Serializable {
private static final long serialVersionUID = -1429681347817644570L;
#Id
#GeneratedValue(strategy=GenerationType.IDENTITY)
#Column(name="key_id")
private long keyId;
#Column(name="key_name")
private String keyName;
#ManyToOne
#JoinColumn(name="tweet_id")
private Tweet tweet;
public long getKeyId() {
return keyId;
}
public void setKeyId(long keyId) {
this.keyId = keyId;
}
public String getKeyName() {
return keyName;
}
public void setKeyName(String keyName) {
this.keyName = keyName;
}
public Tweet getTweet() {
return tweet;
}
public void setTweet(Tweet tweet) {
this.tweet = tweet;
}
}
Here Tweet Entity :
#Entity
#Table(name="tweets")
public class Tweet implements Serializable{
#Id
#Column(name="tweet_id")
private long tweetId;
#Column(name="tweet_text")
private String tweetText;
#Temporal(TemporalType.TIMESTAMP)
#Column(name = "created_at")
private Date createdAt;
#Column(name="lang_code")
private String languageCode;
#ManyToOne
#JoinColumn(name = "user_id")
private User user;
#OneToMany(mappedBy="tweet")
//#JoinColumn(name="hashtag_id")
private List<Hashtag> hashtags;
#OneToMany(mappedBy="tweet")
//#JoinColumn(name="url_id")
private List<Url> urls;
public List<Keyword> getKeywords() {
return keywords;
}
public void setKeywords(List<Keyword> keywords) {
this.keywords = keywords;
}
#OneToMany(mappedBy="tweet")
//#JoinColumn(name="url_id")
private List<Keyword> keywords;
public long getTweetId() {
return tweetId;
}
public void setTweetId(long tweetId) {
this.tweetId = tweetId;
}
public String getTweetText() {
return tweetText;
}
public void setTweetText(String tweetText) {
this.tweetText = tweetText;
}
public Date getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
public String getLanguageCode() {
return languageCode;
}
public void setLanguageCode(String languageCode) {
this.languageCode = languageCode;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public List<Hashtag> getHashtags() {
return hashtags;
}
public void setHashtags(List<Hashtag> hashtags) {
this.hashtags = hashtags;
}
public List<Url> getUrls() {
return urls;
}
public void setUrls(List<Url> urls) {
this.urls = urls;
}
#Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (int) (tweetId ^ (tweetId >>> 32));
return result;
}
#Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Tweet other = (Tweet) obj;
if (tweetId != other.tweetId)
return false;
return true;
}
And here Url entity :
#Entity
#Table(name="tweet_url")
public class Url implements Serializable{
#Id
#GeneratedValue(strategy=GenerationType.IDENTITY)
#Column(name="url_id")
private int urlId;
#Column(name="url")
private String url;
#ManyToOne
#JoinColumn(name="tweet_id",referencedColumnName="tweet_id")
private Tweet tweet;
public int getUrlId() {
return urlId;
}
public void setUrlId(int urlId) {
this.urlId = urlId;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public Tweet getTweet() {
return tweet;
}
public void setTweet(Tweet tweet) {
this.tweet = tweet;
}
And here is hashtag entity :
#Entity
#Table(name="tweet_hashtag")
public class Hashtag implements Serializable{
#Id
#GeneratedValue(strategy=GenerationType.IDENTITY)
#Column(name="hashtag_id")
private int hashtagId;
#Column(name="hashtag")
private String hashtag;
#ManyToOne
#JoinColumn(name="tweet_id",referencedColumnName="tweet_id")
private Tweet tweet;
public int getHashtagId() {
return hashtagId;
}
public void setHashtagId(int hashtagId) {
this.hashtagId = hashtagId;
}
public String getHashtag() {
return hashtag;
}
public void setHashtag(String hashtag) {
this.hashtag = hashtag;
}
public Tweet getTweet() {
return tweet;
}
public void setTweet(Tweet tweet) {
this.tweet = tweet;
}
And the method :
public void batchInsert(List<Keyword> results) throws HibernateException {
// chekeywordck if key exists
// try {
em=RunQuery.emf.createEntityManager();
em.getTransaction().begin();
for(Keyword result:results)
{
try{
em.persist(result.getTweet().getUser());
}
catch(ConstraintViolationException ce)
{
System.out.print("duplicated insert catched");
}
try{
em.persist(result.getTweet());
}
catch(ConstraintViolationException ce)
{
System.out.print("duplicated insert catched");
}
if(result.getTweet().getHashtags()!=null)
for(Hashtag hashtag:result.getTweet().getHashtags())
em.persist(hashtag);
if(result.getTweet().getUrls()!=null)
for(Url url:result.getTweet().getUrls())
em.persist(url);
em.persist(result);
em.flush();
em.clear();
//when I put these two line out of this loop, it still is the same.
}
em.getTransaction().commit();
// }
}
And here is the exception :
Exception in thread "Thread-3" javax.persistence.PersistenceException: org.hibernate.PersistentObjectException: detached entity passed to persist: model.twitter.entities.Url
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1763)
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1677)
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1683)
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:1187)
at model.service.QueryResultService.batchInsert(QueryResultService.java:74)
at controller.ResultsController.save(ResultsController.java:125)
at controller.ResultsController.parse(ResultsController.java:89)
at main.TwitterStreamConsumer.run(TwitterStreamConsumer.java:41)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.hibernate.PersistentObjectException: detached entity passed to persist: model.twitter.entities.Url
at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:139)
at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:75)
at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:811)
at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:784)
at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:789)
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:1181)
... 5 more
To answer your question: your model defines a one-to-many relationship between Tweet and URL without any cascading. When you are passing a Tweet instance for persisting, the URL objects have not yet been saved and your model does not mandate Tweet to cascade the persist operation to the URL instances. Therefore it can not create the relationship with them.
Cascading tells the hibernate, how to execute DB operations on related entities.
You can instruct it to pass/cascade the persist operation to the related entity, to cascade all operations or an array of operations.
That being said, your problem(1 of them) could be fixed if you modify the relationship with cascading info:
#OneToMany(mappedBy="tweet", cascade={CascadeType.PERSIST})
private List<Url> urls;
But your sample indicates other possible issues and I would encourage you to spent some more time reading Hibernate ORM documentation and practicing on sample model with less relationships.
One of the obvious issues seems to be the lack of understanding of relationship owner concept.
For example, in your Tweet-to-Url relationship, URL is the relationship owner(responsible for managing the relationship, e.g. managing the link via foreign key)
Please consult hibernate docs or one of hundreds of similar questions here on SO for more info.
Depending on how you fill the data, it is possible that you will run into constraint issues, or your entities will not be linked together, because you are not saving the owning side.
Also using try/catch for constraint violations is a very bad way of detecting duplicated entries. ConstraintViolationException can be have many causes and the reason you are getting them is related to the above mentioned relationship mapping issues.
ORM is complex subject and it is really beneficial to start with smaller examples, trying to understand the framework mechanics before moving to the more challenging models. Good Luck
For all the persist calls try using this instead:
if(result.getTweet().getUser().getId() == null) {
em.persist(result.getTweet().getUser());
} else {
result.getTweet().setUser(em.merge(result.getTweet().getUser()));
}
if(result.getTweet().getId() == null) {
em.persist(result.getTweet());
} else {
result.setTweet(em.merge(result.getTweet()));
}
if(result.getId() == null) {
em.persist(result);
} else {
result = em.merge(result);
}

Can't insert more than 1 entity (batch insert) with Azure - JAVA

I am trying to insert a batch of Entities with Azure.
For my "CustomerEntity", all works as expected, but for my "OrderEntity", I can only have a single entity in my batch operation...
Here is my code:
public void batchInsertTransaction(ArrayList<Transaction> transactions){
try
{
// Retrieve storage account from connection-string.
CloudStorageAccount storageAccount =
CloudStorageAccount.parse(storageConnectionString);
// Create the table client.
CloudTableClient tableClient = storageAccount.createCloudTableClient();
// Define a batch operation.
TableBatchOperation batchCustomerOperation = new TableBatchOperation();
TableBatchOperation batchOrderOperation = new TableBatchOperation();
// Create a cloud table object for the table.
CloudTable cloudCustomerTable = tableClient.getTableReference("Customer");
CloudTable cloudOrderTable = tableClient.getTableReference("Order");
String partitionKey = "transaction-" + PropertiesManager.country + "-" + PropertiesManager.city;
for(int i = 0; i < transactions.size(); i++){
Transaction transaction = transactions.get(i);
Order order = transaction.getOrder();
Customer customer = transaction.getCustomer();
// Create a customer entity to add to the table.
CustomerEntity customerEntity = new CustomerEntity(partitionKey, customer.getGlobalId());
customerEntity.setCountry(customer.getCountry());
customerEntity.setName(customer.getName());
customerEntity.setGlobalId(customer.getGlobalId());
batchCustomerOperation.insertOrReplace(customerEntity);
OrderEntity orderEntity = new OrderEntity(partitionKey, order.getGlobalId());
orderEntity.setComplete(order.getComplete());
orderEntity.setCustomerId(order.getCustomerId());
orderEntity.setGlobalId(order.getGlobalId());
orderEntity.setOrderDate(order.getOrderDate());
orderEntity.setPrice(order.getPrice());
orderEntity.setSku(order.getSku());
orderEntity.setId(order.getId());
batchOrderOperation.insertOrReplace(orderEntity);
}
// Execute the batch of operations on the "people" table.
cloudCustomerTable.execute(batchCustomerOperation);
cloudOrderTable.execute(batchOrderOperation);
}
catch (Exception e)
{
// Output the stack trace.
e.printStackTrace();
}
}
Here is my "OrderEntity"
package entities;
import com.microsoft.azure.storage.table.TableServiceEntity;
public class OrderEntity extends TableServiceEntity {
int orderId;
int customerId;
String globaOrderlId;
String sku;
String orderDate;
double price;
int complete;
public OrderEntity(){ }
public OrderEntity(String partitionKey, String globalId){
this.partitionKey = partitionKey;
this.rowKey = globalId;
}
public void setComplete(int complete){
this.complete = complete;
}
public void setCustomerId(int id){
this.customerId = id;
}
public void setGlobalId(String id){
this.globaOrderlId = id;
}
public void setPrice(double price){
this.price = price;
}
public void setOrderDate(String date){
this.orderDate = date;
}
public void setSku(String sku){
this.sku = sku;
}
public void setId(int id){
this.orderId = id;
}
public String getGlobalId(){
return this.globaOrderlId;
}
public int getId(){
return this.orderId;
}
public int getCustomerId(){
return this.customerId;
}
public String getSku(){
return this.sku;
}
public String getOrderDate(){
return this.orderDate;
}
public double getPrice(){
return this.price;
}
public int getComplete(){
return this.complete;
}
}
I have tried commenting out the customer code, as well as all of the order entity set properties, but still... I can only have a single entity in my "batchOrderOperation".
If I have any more, I get an error:
com.microsoft.azure.storage.table.TableServiceException: Bad Request at
com.microsoft.azure.storage.table.TableBatchOperation$1.postProcessResponse(TableBatchOperation.java:548)
at com.microsoft.azure.storage.table.TableBatchOperation$1.postProcessResponse(TableBatchOperation.java:434)
at com.microsoft.azure.storage.core.ExecutionEngine.executeWithRetry(ExecutionEngine.java:148)
at com.microsoft.azure.storage.table.TableBatchOperation.execute(TableBatchOperation.java:419)
at com.microsoft.azure.storage.table.CloudTable.execute(CloudTable.java:495)
at com.microsoft.azure.storage.table.CloudTable.execute(CloudTable.java:452)
at managers.TableManager.batchInsertTransaction(TableManager.java:120)
at managers.QueueManager.process(QueueManager.java:40)
at App.main(App.java:32)
Does anyone know what the problem is?
Funny how I spend hours looking for the solution and as soon as I resort to asking for help, I find the answer...
It turns out that my rowKeys were identical, and rowKeys must be unique for any given partition:
http://msdn.microsoft.com/en-us/library/dd179338.aspx
The row key is a unique identifier for an entity within a given
partition
Hope this helps someone else one day.

How to join non primary key in google app engine

How to get data of non primary key column userId using java in google app engine
List<UserAddress> list = (List<UserAddress>) pmf.getObjectById(UserAddress.class, Long.valueOf(userId));
System.out.println(list.size());
When I fetch the data the following error occur in console
NestedThrowablesStackTrace:
Could not retrieve entity of kind UserAddress with key UserAddress(4)
org.datanucleus.exceptions.NucleusObjectNotFoundException: Could not retrieve entity of kind UserAddress with key UserAddress(4)
Tried below code also, to fetch the data of non primary key column userId but it shows empty list.
#SuppressWarnings("unchecked")
public List<UserAddress> getUserAddressFind(String userId) {
List<UserAddress> returnList = new ArrayList<UserAddress>();
PersistenceManager pmf = PMF.get().getPersistenceManager();
try {
Query query = pmf.newQuery(UserAddress.class);
query.setFilter("userId == userIdParam");
query.declareParameters("Long userIdParam");
returnList = (List<UserAddress>) query.execute(userId);
System.out.println(returnList.size());
if (returnList != null && returnList.isEmpty()) {
System.out.println("No results for userAddresses");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
pmf.close();
}
return returnList;
}
UserAddress.java
package com.rrd.up2me.datastore;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
#PersistenceCapable(identityType = IdentityType.APPLICATION)
public class UserAddress {
#PrimaryKey
#Persistent(valueStrategy = IdGeneratorStrategy.SEQUENCE)
private Long userAddressId;
#Persistent
private Long userId;
#Persistent
private Long addressId;
#Persistent
private Boolean isPrimary;
public Long getUserAddressId() {
return userAddressId;
}
public void setUserAddressId(Long userAddressId) {
this.userAddressId = userAddressId;
}
public Long getUserId() {
return userId;
}
public void setUserId(Long userId) {
this.userId = userId;
}
public Long getAddressId() {
return addressId;
}
public void setAddressId(Long addressId) {
this.addressId = addressId;
}
public Boolean getIsPrimary() {
return isPrimary;
}
public void setIsPrimary(Boolean isPrimary) {
this.isPrimary = isPrimary;
}
}
In UserAddress.java class userId is long when execute the query passed variable type is Stringso data is not fetching. AfterType cast the userId String to Long problem solved.
Ex: Long.valueOf(userId).
Query query = pmf.newQuery(UserAddress.class);
query.setFilter("userId == userIdParam");
query.declareParameters("Long userIdParam");
returnList = (List<UserAddress>) query.execute(Long.valueOf(userId));
System.out.println(returnList.size());

Primary key is not generated in JPA with app engine Java

I have entity class "User" as shown below but its not generating primary key. I am using JPA in my app engine application and using app engine endpoints in my android client.
Enitty class:
#Entity
public class UserMaster {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Long userId;
private String userName;
private String fullName;
private String userAvtarUrl;
private String userAbout;
private String userGender;
public String getUserName() {
return userName;
}
public Long getUserId() {
return userId;
}
public void setUserId(Long userId) {
this.userId = userId;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getFullName() {
return fullName;
}
public void setFullName(String fullName) {
this.fullName = fullName;
}
public String getUserAvtarUrl() {
return userAvtarUrl;
}
public void setUserAvtarUrl(String userAvtarUrl) {
this.userAvtarUrl = userAvtarUrl;
}
public String getUserAbout() {
return userAbout;
}
public void setUserAbout(String userAbout) {
this.userAbout = userAbout;
}
public String getUserGender() {
return userGender;
}
public void setUserGender(String userGender) {
this.userGender = userGender;
}
}
Endpoint persistence code :
#ApiMethod(name = "insertUserMaster")
public UserMaster insertUserMaster(UserMaster usermaster) {
EntityManager mgr = getEntityManager();
try {
if (containsUserMaster(usermaster)) {
throw new EntityExistsException("Object already exists");
}
mgr.persist(usermaster);
} finally {
mgr.close();
}
return usermaster;
}
Android client
Userendpoint.Builder builder = new Userendpoint.Builder(
AndroidHttp.newCompatibleTransport(),
new JacksonFactory(), new HttpRequestInitializer() {
public void initialize(HttpRequest httpRequest) {
}
});
Userendpoint endpoint = CloudEndpointUtils.updateBuilder(
builder).build();
User objUser = new User();
objUser.setUserName(txtName.getText().toString());
objUser.setUserEmail(txtEmail.getText().toString());
Bitmap bmp = BitmapFactory.decodeFile(imagePath);
ByteArrayOutputStream out = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, out);
byte[] imgByte = out.toByteArray();
String encodedImage = Base64.encodeToString(imgByte,
Base64.DEFAULT);
objUser.setImage(encodedImage);
User result = endpoint.insertUser(objUser).execute();
Please guide me where i am lacking. Thank you.
If using JPA and GAE/Datastore either use all JPA annotations, or all as a vendor-extension use all JDO annotations. You cannot mix and match.
May be your database server does not provide the auto id generation.
IDENTITY
IDENTITY, it is depend on the Database to auto generate.
Some DB Server Like, MySQL or Microsoft SQL Server do provide ID generation for the primary key field during insertion.
The common way is to use the IdGeneratorStrategy.TABLE. It is not depend on DB.
In my case problem was in method "containsUserMaster(usermaster)"
Method check existing in way like this:
UserMaster item = mgr.find(UserMaster.class, userId);
Problem that until add operation not complete, userId will be null, and because program stops with NullPointerExeption..
I'm add userId checkinq on null - and this solves the problem

Categories