[JBoss Seam] - question about components and persistence
by gsegura
Hello, I'm having problems to get same during method invocation, I mean:
there is the class User which has a collection of items.
- One instance of user is maintained during session,
- then there is this action method which adds an item to the user's collection
- there is also another method which ask question about items in the users collection,
the problem is that the user instance is not the same in those methods, so the collection has not the same data. I've tried using merge at the beginning of those methods but an OptimisticLockException is thrown. here is my code so far:
@Scope(ScopeType.CONVERSATION)
| @Name("exam")
| @Restrict("#{identity.loggedIn}")
| public class ExamAction implements Evaluacion {
| //injected from user in session
| @In(required = true)
| @Out
| private User user;
|
|
| @End
| public void calificate() {
| //... calculate calification, then:
| Calification cal = user.setCalificacion(course, points) ;
|
| Calification mergedcal = entityManager.merge(cal) ;
| entityManager.persist(cal) ;
| }
|
| public boolean isExamDone() {
| // this throws OptimisticLockException, casued by StaleObjectStateException
| //but without this the user (hashcode) is different than the one injected in method calificate
| //so I'm confused :S
|
| User mergedUser = entityManager.merge(user) ;
| Calification cal = mergedUser.findCalificacion(course) ;
| return cal.getCalificacionEvaluacion()!=null ;
| }
| }
|
@Entity
| @Table(name = "user", catalog = "test1")
| public class User implements java.io.Serializable {
|
| @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "user")
| public Set<Calification> getCalificacions() {
| return this.calificacions;
| }
|
| public void setCalificacions(Set<Calification> calificacions) {
| this.calificacions = calificacions;
| }
|
| public Calification findCalificacion(Course course) {
| for(Calification c : getCalificacions())
| if(c.getId().getIdCourse()==course.getId())
| return c ;
| throw new NoSuchElementException(
| new StringBuilder(52)
| .append("course ")
| .append(course.getId())
| .append(", not found for user ")
| .append(getId()).toString()) ;
| }
|
| public Calification setCalificacion(Course course, int points) {
| Calification c = null ;
| try {
| c = findCalificacion(course) ;
| } catch(NoSuchElementException e) {
| c = new Calification(this, course, 0) ;
| getCalificacions().add(c) ;
| }
|
| c.setPoints(points) ;
| return c ;
| }
| }
so the question is, how can I modify the user's collection of items and access same collection every time (I tried outjecting user but no effect) or how can I synchronize those objects before using them?
please, I really appreciate some advice here
regards
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4109964#4109964
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4109964
18 years, 4 months
[JBoss Seam] - Dataimport in Seam tests
by hispeedsurfer
Hi,
project is created with seam-gen v.2.0.0.GA
Production DB is MySQL
For testing purpose I filled import-test.sql with values
INSERT INTO Customer (id, version, userName, hashedPassword, email, memberName) VALUES
| (1, 1, 'feivel', 'd41d8cd98f00b204e9800998ecf8427e', 'a.franke(a)email.de', '00022')
Here the corresponding entity
| @Entity
| @Name("user")
| @Table(name = "Customer")
| public class User implements java.io.Serializable {
|
| private Long id;
| private Long version;
| private String userName;
| private String memberName;
| private String email;
| private String hashedPassword;
|
| @Id
| @GeneratedValue(strategy = IDENTITY)
| @Column(name = "id", unique = true, nullable = false)
| public Long getId() {return this.id;}
| public void setId(Long id) {this.id = id;}
|
| @Version
| @Column(name = "version")
| public Long getVersion() {return this.version;}
| public void setVersion(Long version) {this.version = version;}
|
| @Column(name = "userName", nullable = false)
| @NotNull
| public String getUserName() {return this.userName;}
| public void setUserName(String username) {this.userName = username;}
| ......
| }
|
But when I run a login-test the values not in HSQLDB
@Test
| public void testLoginComponent() throws Exception
| {
| new ComponentTest() {
|
| @Override
| protected void testComponents() throws Exception
| {
| assert getValue("#{identity.loggedIn}").equals(false);
| setValue("#{identity.username}", "00022");
| setValue("#{identity.password}", "");
| invokeMethod("#{identity.login}");
| assert getValue("#{identity.loggedIn}").equals(true);
| invokeMethod("#{identity.logout}");
| assert getValue("#{identity.loggedIn}").equals(false);
| setValue("#{identity.username}", "gavin");
| setValue("#{identity.password}", "tiger");
| invokeMethod("#{identity.login}");
| assert getValue("#{identity.loggedIn}").equals(false);
| }
|
| }.run();
| }
@Stateless
| @Name("authenticator")
| public class AuthenticatorBean implements Authenticator
| {
| @Logger
| private Log log;
|
| @PersistenceContext
| private EntityManager entityManager;
|
| @In
| private Identity identity;
|
| @Out(required=false, scope=ScopeType.SESSION)
| private User currentUser;
|
| public boolean authenticate(){
| log.info("authenticating #0", identity.getUsername());
| try {
| List results = entityManager.createQuery("select u from User u where u.memberName =:username").setParameter("username", identity.getUsername()).getResultList();
| if ( results.size()==0 )
| {
| return false;
| }
| else
| {
| currentUser = (User) results.get(0);
| }
| } catch (PersistenceException e) {
| e.printStackTrace();
| return false;
| }
| .....
In debug-modus I can see that the returned list from entityManager is empty, also I call "from User u" in sql statement.
I found nothing in docu or forum what I have done wrong. The persistence-test.xml is that one created automatically from Seam
<?xml version="1.0" encoding="UTF-8"?>
| <!-- Persistence deployment descriptor for tests -->
| <persistence xmlns="http://java.sun.com/xml/ns/persistence"
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
| xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
| version="1.0">
|
| <persistence-unit name="datenvisualisierung">
| <provider>org.hibernate.ejb.HibernatePersistence</provider>
| <jta-data-source>java:/DefaultDS</jta-data-source>
| <properties>
| <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
| <property name="hibernate.show_sql" value="true"/>
| <property name="hibernate.cache.use_second_level_cache" value="false"/>
| <property name="jboss.entity.manager.factory.jndi.name" value="java:/datenvisualisierungEntityManagerFactory"/>
| </properties>
| </persistence-unit>
|
| </persistence>
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4109958#4109958
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4109958
18 years, 4 months
[JBoss Seam] - Re: SEAM Logger issue
by wayofdragonster
My understanding is that you can configure your log4j settings in log4j.properties under (myapp)/WEB-INF/classes and then jboss 4.2.1 would automatically read it. Is this incorrect? Do I have to do something special in jboss-log4j.xml to make it load log4j.properties in my app?
Here is my log4j.properties file:
log4j.rootLogger=CONSOLE,FILE,genesisOut
log4j.logger.com.genesis=DEBUG
log4j.appender.genesisOut=org.apache.log4j.DailyRollingFileAppender
log4j.appender.genesisOut.DatePattern='.'yyyy-MM-dd
log4j.appender.genesisOut.File=C:\programs\jboss-4.2.1.GA\server\default\log\genesis.log
log4j.appender.genesisOut.layout=org.apache.log4j.PatternLayout
log4j.appender.genesisOut.layout.ConversionPattern=%1p %d{MMM-dd HH:mm:ss,SSS} %x %m [%t](%c{3})%n
What am I doing wrong? I still don't see anything in server.log nor is genesis.log being generated.
Paul
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4109948#4109948
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4109948
18 years, 4 months