Reputation: 936
Here are my models.
User:
@Entity
@Table(name="users")
public class User extends Model {
String username;
@Id
String id;
@OneToMany(cascade = CascadeType.ALL)
List<Tag> tags;
}
Tag:
@Entity
@Table(name="tags")
public class Tag extends Model {
@Constraints.Required
public String tag;
}
Persistence code(Removed unnecessary code):
User user = new User();
user.id = UUID.randomUUID().toString();
user.username = username; // String
user.tags = tags; // list of tags;
Ebean.save(user);
I am calling Ebean.save(user) after adding tags to user object. Tags added on user are not persisted to database. I am also not seeing any exception, other fields of user get persisted but not tags. Am I missing something?
Note: I am using postgres.
Upvotes: 1
Views: 193
Reputation: 936
Thanks for the suggestion @marcospereira. I was missing id field in Tag model. After enabling debugging and sql logging I noticed warning in logs. The correct way to create Tag class:
@Entity
@Table(name="tags")
public class Tag {
@Id
@GeneratedValue
public String id;
public String tag;
}
but It is weird why Ebean is doing that.
Hope this helps someone in future.
Upvotes: 1