I have a weird problem with remote EJB. Here is an entity:
@Entity
@Table(name="cd")
@AttributeOverrides({
@AttributeOverride(name = "id", column = @Column(name = "cd_id")),
@AttributeOverride(name = "title", column = @Column(name = "cd_title")),
@AttributeOverride(name = "description", column = @Column(name = "cd_description"))
})
@NamedQueries({
@NamedQuery(name = "findAllCDs", query = "SELECT cd FROM CD cd")
})
public class CD extends Item implements Serializable{
private String musicCompany;
private Integer numberOfCDs;
private Float totalDuration;
private String genre;
public CD(String title, Float price,String description, String musicCompany,
Integer numberOfCDs, Float totalDuration, String genre) {
super(title, price, description);
this.musicCompany = musicCompany;
this.numberOfCDs = numberOfCDs;
this.totalDuration = totalDuration;
this.genre = genre;
}
And mapped superclass:
@MappedSuperclass
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class Item {
@Id
@GeneratedValue
protected Long id;
@NotNull
@Column(name="title",nullable = false,updatable = false)
protected String title;
protected Float price;
@Size(min = 10,max=2000)
@Column(length = 2000)
protected String description;
I am trying to persist it using the Following ejb:
@Stateless
@LocalBean
public class ItemEJB implements ItemLocal,ItemRemote{
@PersistenceContext(unitName = "demo_unit")
private EntityManager em;
@Override
public List<Book> findBooks() {
TypedQuery<Book> query = em.createNamedQuery("findAllBooks", Book.class);
return query.getResultList();
}
@Override
public List<CD> findCDs() {
TypedQuery<CD> query = em.createNamedQuery("findAllCDs", CD.class);
return query.getResultList();
}
@Override
public Book createBook(Book book) {
em.persist(book);
return book;
}
@Override
public CD createCD(CD cd) {
em.persist(cd);
return cd;
}
}
The problem is with this remote interface:
@Remote
public interface ItemRemote {
List<Book> findBooks();
List<CD> findCDs();
Book createBook(Book book);
CD createCD(CD cd);
}
When I am trying to persist an Entity like this:
CD cd = new CD("Love SUpreme", 20f, "John Coltrane love moment",
"Blue Note", 2, 87.45f, "Jazz");
cd = itemRemote.createCD(cd);
I am getting
ConstraintViolationImpl{interpolatedMessage='may not be null', propertyPath=title, rootBeanClass=class org.abondar.experimental.javaeedemo.ejbdemo.model.CD, messageTemplate='{javax.validation.constraints.NotNull.message}'}
When I am doing the same with local or just stateless ejb everything works fine. The problem is exactly with remote one. What may I have misconfigured?