-
1. Re: Problems with Faces + Persistence... Example available?
elfuhrer May 18, 2011 5:35 AM (in response to tandraschko)Can you post your code? I have managed already to run a JPA 2 persistence example within tomcat using Seam 3
-
2. Re: Problems with Faces + Persistence... Example available?
tandraschko May 18, 2011 7:19 AM (in response to tandraschko)Thanks! I will upload my test project later :)
-
3. Re: Problems with Faces + Persistence... Example available?
tandraschko May 18, 2011 1:23 PM (in response to tandraschko)I uploaded the example here:
http://www.megaupload.com/?d=8173QR4O
You can simple call mvn package jetty:run und open localhost:8080/my-webapp/index.xhtml
Thanks for your help
-
4. Re: Problems with Faces + Persistence... Example available?
piklos May 19, 2011 3:23 AM (in response to tandraschko)First of all you got this in beans.xml
<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:s="urn:java:ee" xmlns:t="urn:java:org.jboss.seam.transaction" xsi:schemaLocation=" http://java.sun.com/xml/ns/javaee http://docs.jboss.org/cdi/beans_1_0.xsd"> <interceptors> <class>org.jboss.seam.transaction.TransactionInterceptor</class> </interceptors> <t:SeSynchronizations> <s:modifies /> </t:SeSynchronizations> <t:EntityTransaction> <s:modifies /> </t:EntityTransaction> </beans>
That is wrong, you should be having:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"> <interceptors> <class>org.jboss.seam.transaction.TransactionInterceptor</class> </interceptors> </beans>
In your beans.xml and you should have a file called seam-beans.xml that has this:
<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:s="urn:java:ee" xmlns:t="urn:java:org.jboss.seam.transaction" xsi:schemaLocation=" http://java.sun.com/xml/ns/javaee http://docs.jboss.org/cdi/beans_1_0.xsd"> <t:SeSynchronizations> <s:modifies /> </t:SeSynchronizations> <t:EntityTransaction> <s:modifies /> </t:EntityTransaction> </beans>
Then in the class UserDaoImpl you have this:
@Singleton @SuppressWarnings("serial") public class UserDaoImpl implements UserDao, Serializable { @PersistenceContext @Inject private EntityManager entityManager;
You dont need @PersistenceContext it won't even work on tomcat. So remove it and use only @Inject. Also you shouldn't use @Singleton for the bean scope, use @ApplicationScoped. After those couple of things i think you should be fine, if not writte here again.
Good luck.
-
5. Re: Problems with Faces + Persistence... Example available?
piklos May 19, 2011 3:27 AM (in response to tandraschko)And yeah you need this in your pom.xml
<dependency> <groupId>org.jboss.seam.persistence</groupId> <artifactId>seam-persistence</artifactId> <version>3.0.0.Final</version> </dependency> <dependency> <groupId>org.jboss.seam.config</groupId> <artifactId>seam-config-xml</artifactId> <version>3.0.0.Final</version> <scope>runtime</scope> </dependency> <dependency> <groupId>org.jboss.seam.solder</groupId> <artifactId>seam-solder</artifactId> <version>3.0.0.Final</version> </dependency>
-
6. Re: Problems with Faces + Persistence... Example available?
tandraschko May 19, 2011 4:57 AM (in response to tandraschko)Great, it works :D Thanks!
I also tried it with seam-beans.xml but apparently i forgot to add the seam-config-xml module :/But there is another problem:
If i add a user the first time, it works without problems but if i add another user it does not work anymore.
Is this a problem of the persistence module or is it really hibernate? (I also tried Hibernate 3.5.1)Caused by: java.sql.SQLException: Violation of unique constraint $$: duplicate value(s) for column(s) $$: SYS_CT_46 in statement [insert into Users (id, email, loginName, password, status) values (null, ?, ?, ?, ?)] at org.hsqldb.jdbc.Util.throwError(Unknown Source) at org.hsqldb.jdbc.jdbcPreparedStatement.executeUpdate(Unknown Source) at org.hibernate.id.insert.AbstractSelectingDelegate.performInsert(AbstractSelectingDelegate.java:57) ... 91 more
@Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "id", nullable = false) private Long id;
p:commandButton actionListener="#{testController.newUser}"
@Transactional public void newUser() { User user = new User(); user.setPassword("blublublubl"); user.setEmail("asdas@asdas.com"); user.setLoginName("testLogin"); user.setStatus(1); userDao.persist(user); }
Any ideas?
-
7. Re: Problems with Faces + Persistence... Example available?
piklos May 19, 2011 5:29 AM (in response to tandraschko)<dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-entitymanager</artifactId> <version>3.6.0.Final</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.hibernate.javax.persistence</groupId> <artifactId>hibernate-jpa-2.0-api</artifactId> <version>1.0.0.Final</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-validator</artifactId> <version>4.0.0.GA</version> </dependency>
I use this combination and it works.
Try it. -
8. Re: Problems with Faces + Persistence... Example available?
tandraschko May 19, 2011 6:51 AM (in response to tandraschko)Argh!
it was my mistake - loginname is declared as unique!Sorry and thanks for your help :)