[JBoss Seam] - Injection of Session javabean into event javabean not workin
by joeyxxx
I'm running 1.2.1 with facelets on JBoss 4.05 EJB3 profile and using pojos not EJBs. This is my first attempt at seam and the ff issue has thrown me for a bit of a loop.
The user component injected into balance is always null and it seams that I can only reference it is explictly using the ff
(User) Contexts.getSessionContext().get("user");
| @Name("user")
| @Scope(SESSION)
| public class User implements Serializable
| {
| private String userName;
| private String password;
| private String userRole;
| private String segment;
| private String firstName;
| private String lastName;
| private String destination;
|
| public User(String firstName, String lastName, String userName, String password)
| {
| this.firstName = "James";
| this.lastName = "Bond";
| this.password = password;
| this.setUserName(userName);
| this.setUserRole("Investor");
| }
|
| public User() {}
|
|
|
| @Name("balance")
| @Scope(EVENT)
| public class Balance implements Serializable
| {
| private double totalMarketValue;
| private double cash;
| private double margin;
| private String userName;
| @In
| private User user;
| @Logger Log log;
|
| public Balance() {
| this.setTotalMarketValue(0);
| this.setMargin(0);
| this.setCash(0);
| if(user!=null){
| this.setUserName("Balance User:"+this.user.getUserName());
| } else {
| //This always works!!!
| user = (User) Contexts.getSessionContext().get("user");
| this.setUserName("Null @In "+this.user.getUserName());
| }
| }
|
|
Are there any disadvantages to using javabeans instead of EJBs if one doesn't care about transactions etc? Is clustering better with EJBs on JBoss?
Thanks
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4045333#4045333
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4045333
19 years, 1 month
[JBoss Seam] - Asynchronous programming pattern
by xtia004
Whenever we make an asynchronous method call, a thread will be dispatched. It works well so far but we encountered serveral asynchronous call requirements such as doing calculation when rolling over a day, sending reminder message for a payment due, expiring a registration for certain condition. A scheduled task might be cancelled in the middle, say, a payment made after the reminder scheduled to send but before actually sending it.
Firstly we just simple make a asynchronous call when needed, but it turns out there are too many threads running. We worry about the performance and resources even though we haven't experienced them yet. We tried to make only one asynchronous call with interval at every 5 minutes. The other scheduled tasks are registered with it, and the tasks will mature within 5 minutes will be dispatched with a one-off asynchronous call by this thread. The problem here is that the one-off asynchronous calls run immidiately and the expiration or duration totally get ignored. Thus the scheduled time might have discrepancy in 5 minutes.
Does Seam support to make an asynchronous call from another asynchronous call? Or has anybody got another programming pattern to fulfill such kind of requirements. In case I incorrently programmed the asynchronous feature, I pasted the code below:
| //Making an asynchronous call to look after the other scheduled tasks
|
| @Name("scheduleDispatcherAction")
| @Scope(ScopeType.APPLICATION)
| @Synchronized
| @Startup
| public class ScheduleDispatcherAction implements ScheduleDispatcher, Serializable {
|
| @In(create = true)
| private ScheduleService scheduleServiceAction;
|
| @Create
| public void startService() {
| ...
| scheduleServiceAction.dispatchTasks(cal.getTime(), ScheduleService.INTERVAL_MILLIS);
|
| cal.add(Calendar.MINUTE, 1);
| ScheduledTask task = new ScheduledTask(new Long(1), cal.getTime(), 45000, "miscAction", "test1", null);
| ScheduleServiceAction.addTask(task);
| cal.add(Calendar.MINUTE, 1);
| task = new ScheduledTask(new Long(2), cal.getTime(), 0, "miscAction", "test2", null);
| ScheduleServiceAction.addTask(task);
| }
|
| //The method to dispatch the scheduled tasks
|
| @Name("scheduleServiceAction")
| @Scope(ScopeType.APPLICATION)
| @Synchronized
| public class ScheduleServiceAction implements ScheduleService, Serializable {
|
| @Asynchronous
| public void dispatchTasks(@Expiration Date startDate, @IntervalDuration long interval) {
| Iterator<ScheduledTask> iter = taskPool.iterator();
| while (iter.hasNext()) {
| ScheduledTask aTask = iter.next();
| long dueMillis = aTask.getStartDate().getTime() - System.currentTimeMillis();
| if (dueMillis > ScheduleService.INTERVAL_MILLIS) {
| break;
| } else if (dueMillis < 0) {
| dueMillis = 0;
| }
|
| Object action = Component.getInstance(aTask.getActionName(), ScopeType.APPLICATION);
| Method method = action.getClass().getMethod(aTask.getMethodName(), new Class[]{long.class, Object[].class});
| method.invoke(action, dueMillis, aTask.getParameters());
| // It's the same result if not using reflection here.
| ...
|
| //Task code
|
| @Name("miscAction")
| @Scope(ScopeType.APPLICATION)
| @Synchronized
| public class MiscAction implements MiscService, Serializable {
|
| @Asynchronous
| public void test1(@Duration long duration, Object[] paras) {;
| System.out.println("test1 started at " + (new Date()));
| }
|
| @Asynchronous
| public void test2(@Duration long duration, Object[] paras) {
| System.out.println("test2 started at " + (new Date()));
| }
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4045329#4045329
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4045329
19 years, 1 month
[EJB 3.0] - Hibernate3: Cannot simultaneously fetch multiple bags
by ericmacau
Hello,
I don't know why it will raise the "Cannot simultaneously fetch multiple bags" exception, please help and teach me how can I solve the problem?
| @Entity
| @Table(name="EventNotes")
| public class Notes implements Serializable {
| public static final long serialVersionUID = 1L;
|
| protected long id;
| protected User creator;
|
|
| /**
| * @return the creator
| */
| @ManyToOne( cascade = {CascadeType.PERSIST, CascadeType.MERGE} )
| @JoinTable(name="USER_NOTES",
| joinColumns = @JoinColumn(name="NOTES_ID"),
| inverseJoinColumns = @JoinColumn(name="USER_ID")
| )
| public User getCreator() {
|
| return this.creator;
| }
|
| /**
| * @param creator the creator to set
| */
| public void setCreator(User creator) {
|
| this.creator = creator;
| }
|
|
|
| /**
| * @return the id
| */
| @Id
| @GeneratedValue(strategy = GenerationType.AUTO)
| public long getId() {
|
| return this.id;
| }
|
| /**
| * @param id the id to set
| */
| public void setId(long id) {
|
| this.id = id;
| }
|
|
| }
|
| @Entity
| @Table(name="USERS")
| public class User implements Serializable {
| public static final long serialVersionUID = 1L;
|
| private String username;
|
| private String password;
|
|
| private String firstName;
| private String lastName;
| private String displayName;
| private String gender;
|
|
| private boolean activate;
|
| private Collection<Role> roles = new ArrayList<Role>();
| private Collection<Group> groups = new ArrayList<Group>();
|
|
|
|
| @Transient
| public boolean isActivate() {
| return activate;
| }
|
|
| public boolean getActivate() {
| return activate;
| }
|
| public void setActivate(boolean activate) {
| this.activate = activate;
| }
|
| public String getPassword() {
| return password;
| }
|
| public void setPassword(String password) {
| this.password = password;
| }
|
| @Id
| //@GeneratedValue(strategy = GenerationType.AUTO)
| public String getUsername() {
| return username;
| }
|
| public void setUsername(String username) {
| this.username = username;
| }
|
|
|
| public String getFirstName() {
| return firstName;
| }
|
| public void setFirstName(String firstName) {
| this.firstName = firstName;
| }
|
| public String getLastName() {
| return lastName;
| }
|
| public void setLastName(String lastName) {
| this.lastName = lastName;
| }
|
|
|
|
| public String getDisplayName() {
| return displayName;
| }
|
| public void setDisplayName(String displayName) {
| this.displayName = displayName;
| }
|
|
|
|
|
| public String getGender() {
| return gender;
| }
|
| public void setGender(String gender) {
| this.gender = gender;
| }
|
| @ManyToMany(cascade = {CascadeType.REMOVE},
| fetch = FetchType.EAGER,
| targetEntity=Role.class)
| @JoinTable(
| name="USER_ROLE_LINK",
| joinColumns={@JoinColumn(name="username")},
| inverseJoinColumns={@JoinColumn(name="rolename")}
| )
| public Collection<Role> getRoles() {
| return roles;
| }
|
|
| public void setRoles(Collection<Role> roles) {
| this.roles = roles;
| }
|
| @Transient
| public void addRole(Role role) {
| this.roles.add(role);
| }
|
|
| @ManyToMany(cascade = {CascadeType.REMOVE},
| fetch = FetchType.LAZY,
| targetEntity=Group.class)
| @JoinTable(
| name="USER_GROUP_LINK",
| joinColumns={@JoinColumn(name="username")},
| inverseJoinColumns={@JoinColumn(name="groupname")}
| )
| public Collection<Group> getGroups() {
| return groups;
| }
|
|
|
| public void setGroups(Collection<Group> groups) {
| this.groups = groups;
| }
|
| @Transient
| public void addGroup(Group group) {
| groups.add(group);
| }
|
|
|
| @Transient
| public String toString() {
| StringBuffer buf = new StringBuffer();
|
| buf.append("=== " + username + "===\n");
| buf.append(displayName + "\n");
|
| Iterator rs = roles.iterator();
| while(rs.hasNext()) {
| Role r = (Role)rs.next();
| buf.append(r);
| }
|
| Iterator gs = groups.iterator();
| while(rs.hasNext()) {
| Group g = (Group)rs.next();
| buf.append(g);
| }
|
|
| return buf.toString();
| }
|
| }
|
| javax.persistence.PersistenceException: org.hibernate.HibernateException: cannot simultaneously fetch multiple bags
| at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:737)
| at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:121)
| at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
| at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
| at mo.reales.util.HibernateUtil.initFactory(HibernateUtil.java:40)
| at mo.reales.util.HibernateUtil.initFactory(HibernateUtil.java:35)
| at mo.reales.web.ServiceStartupListener.contextInitialized(ServiceStartupListener.java:69)
| at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3763)
| at org.apache.catalina.core.StandardContext.start(StandardContext.java:4211)
| at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:759)
| at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:739)
| at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:524)
| at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:904)
| at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:867)
| at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:474)
| at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1122)
| at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:310)
| at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
| at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1021)
| at org.apache.catalina.core.StandardHost.start(StandardHost.java:718)
| at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1013)
| at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:442)
| at org.apache.catalina.core.StandardService.start(StandardService.java:450)
| at org.apache.catalina.core.StandardServer.start(StandardServer.java:709)
| at org.apache.catalina.startup.Catalina.start(Catalina.java:551)
| at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
| at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| at java.lang.reflect.Method.invoke(Method.java:585)
| at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:294)
| at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:432)
| Caused by: org.hibernate.HibernateException: cannot simultaneously fetch multiple bags
| at org.hibernate.loader.BasicLoader.postInstantiate(BasicLoader.java:66)
| at org.hibernate.loader.entity.EntityLoader.<init>(EntityLoader.java:75)
| at org.hibernate.loader.entity.EntityLoader.<init>(EntityLoader.java:43)
| at org.hibernate.loader.entity.EntityLoader.<init>(EntityLoader.java:33)
| at org.hibernate.loader.entity.BatchingEntityLoader.createBatchingEntityLoader(BatchingEntityLoader.java:103)
| at org.hibernate.persister.entity.AbstractEntityPersister.createEntityLoader(AbstractEntityPersister.java:1748)
| at org.hibernate.persister.entity.AbstractEntityPersister.createEntityLoader(AbstractEntityPersister.java:1752)
| at org.hibernate.persister.entity.AbstractEntityPersister.createLoaders(AbstractEntityPersister.java:2982)
| at org.hibernate.persister.entity.AbstractEntityPersister.postInstantiate(AbstractEntityPersister.java:2975)
| at org.hibernate.persister.entity.SingleTableEntityPersister.postInstantiate(SingleTableEntityPersister.java:690)
| at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:290)
| at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
| at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:915)
| at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:730)
| ... 30 more
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4045327#4045327
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4045327
19 years, 1 month