Problem by inserting of entities
music Apr 23, 2007 3:49 AM
 Hi,
I use JBoss Seam 1.2.1 GA, Jboss 4.0.5 GA and JSF for one project. I have made one new Session bean for inserting/deleting some data in/from database.
It's look something like this:
@Stateless
@Name("initialize")
public class InitializeData implements Initialize
{
 @PersistenceContext
 private EntityManager em = null;
 public void insertData()
 {
 try
 {
 PriceCategory cat1 = new PriceCategory("Old", new BigDecimal(3.2));
 PriceCategory cat2 = new PriceCategory("New", new BigDecimal(5.2));
 em.persist(cat1);
 em.persist(cat2);
 em.flush();
 }
 catch(Exception e)
 {
 e.printStackTrace();
 }
 }
But when I call this method from JSF, I get always this exception by first em.persist()-call:
09:27:45,078 INFO [STDOUT] Hibernate: insert into PriceCategory (priceCategoryId, name, dailyFee, optLock) values (null, ?, ?, ?) 09:27:45,093 WARN [JDBCExceptionReporter] SQL Error: -104, SQLState: 23000 09:27:45,093 ERROR [JDBCExceptionReporter] Unique constraint violation: SYS_CT_61 in statement [insert into PriceCategory (priceCategoryId, name, dailyFee, optLock) values (null, ? , ?, ?)] 09:27:45,093 ERROR [STDERR] javax.persistence.EntityExistsException: org.hibernate.exception.ConstraintViolationException: could not insert: [model.PriceCategory] 09:27:45,093 ERROR [STDERR] at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:622) 09:27:45,093 ERROR [STDERR] at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:218)
I don't really understand what happend there. Perheps my entity bean PriceCategory:
@Entity
@Table(name = "PriceCategory")
@Name("pricecategory")
public class PriceCategory implements Serializable {
 @Id
 @GeneratedValue(strategy=GenerationType.IDENTITY)
 @Column(name = "priceCategoryId")
 private Integer id;
 @Column(name = "name", nullable = false, length = 20, unique=true)
 private String name;
 @Column(name = "dailyFee", nullable = false, precision = 4, scale = 2)
 private BigDecimal dailyFee;
 @Version
 @Column(name = "optLock")
 private Integer version;
...
I am really stuck at this point and without data in database cann't do anything more.
Could anyone give me some hint for get over it?
Thanks a lot for every help!
 
    