facebook

EJB 3 Tutorial with JBoss

  1. MyEclipse IDE
  2.  > 
  3. Java EE Development (EJB, JSP, Struts, XDoclet, etc.)
Viewing 15 posts - 1 through 15 (of 37 total)
  • Author
    Posts
  • #248658 Reply

    LaLiLuna
    Member

    Hello,
    I have just added an free EJB 3 tutorial to my website. It shows the complete setup with MyEclipse.

    The use of entity beans and a stateless beans is explained step by step.
    I am going to add a Ant setup, a setup for other application server as soon as possible.

    Another tutorial showing Struts and EJB 3 is nearly finished as well.

    Best Regards

    Sebastian
    Hibernate 3 Developer Guide eBook<br>
    Tutorials for JSP, JavaServer Faces, Struts, Hibernate and EJB<br>
    Training and Education at reasonable prices<br>
    Find out more at http://www.laliluna.de

    #248739 Reply

    Riyad Kalla
    Member

    Sebastian,
    This is excellent news, a lot of our users rely on your tutorials to help them learn technologies and tools which is no small feat.

    Do you have a direct link to the tutorial? I checked the English Tutorial section and didn’t see one from March ’06 for EJB in the EJB section, maybe I missed it?

    #248773 Reply

    LaLiLuna
    Member

    Hello,

    here is the link.
    http://www.laliluna.de/EJB-3-tutorials.html

    Regards Sebastian

    #248781 Reply

    Riyad Kalla
    Member

    Great, I will make this thread sticky as I know a lot of folks have been wanting this.

    #248809 Reply

    bryantan
    Member

    It’s great. Thank you Sebastian very much!

    #248988 Reply

    safiqksm
    Member

    Thank you for your contributions.It’s really helpful for us to learn new technologies.

    #249113 Reply

    Pat Osterday
    Member

    Thanks for the tutorial! I’ve learned a lot from the LaLiLuna site. One recommendation I’d make is to add the import (import javax.persistence.*;) to the Book class since it says “this is our full source code now”. Since I didn’t download the source code at first, I was confused by the errors MyEclipse was giving me before adding the import statement.

    Also, for MySQL, you can use @GeneratedValue(strategy = GenerationType.AUTO) and remove the @SequenceGenerator annotation – that worked for me.

    You can get by with a lot less included libs – I couldn’t find some of them, like qdox.jar, but it worked without them.

    Thanks again!

    #249623 Reply

    Pat Osterday
    Member

    Just a little info on which libs are needed… My “EJB3” user lib only has ejb3-persistence.jar and jboss-ejb3x.jar – for Entity and Session beans, this is all I’ve needed so far. For my “JBoss4-Client” user lib, I’ve got a screenshot here: http://www.market-assist.com/~osterday/pics/screenshots/ejb3-userlibs.png.

    Thanks again for the great work Sebastian! (I hope to donate soon!)

    -Pat

    #249737 Reply

    Russ
    Member

    First of all, thank you for a nice tutorial. I am sure I would have not gotten up the learning curve without your insight.

    I am working through your EJB3.0 Ant Tutorial. I have been successful in getting this EJB project to deploy properly in JBOSS4.0.3SP1. In one case I had to strip out the EJB 2.1 jars and conf xml file and drop in the EJB3.0 stuff to make the server work. I know it was not part of your tutorial and JBOS gives some clear instructions on what to do. 🙂

    Here are some things you might want to look at when you update your tutorial.

    1. Creating a Java Project vs. an EJB Project. Your instructions call for creating a Java Project, but your Screen shot shows you created an EJB Project.

    2. The Book class is missing the import statments for the javax.persistence.* classes.

    3. In the session bean add the unitName attribute in the annotation. I changed my around some, just to be different 😉

    
             @PersistenceContext(unitName="Ejb3Demo")
            

    I sure these errors are just the difference between the current code today and the code you used back when you originally created the tutorial.

    Again, thank you for putting together a nice aritcle. I look forward to finishing it and moving onto others.

    Russ

    #249755 Reply

    Scott Anderson
    Participant

    Russ,

    Thanks very much for the feedback; you’ve provided some valuable insights. We’ll be sure the authors see it when we update it next.

    #250148 Reply

    laguiz
    Member

    Hi,

    I have problemes with annotations …

    I have problemes with :

    
    @Entity
    @Table(name="book")
    @SequenceGenerator(name = "book_sequence", sequenceName = "book_id_seq")
    public class Book implements Serializable {
    

    Error is :

    Entity cannot be resolved to a type

    But I haven’t with

    
    @Override
        public String toString() {
    

    Why ? strange …

    Can you help me ?

    Thanks !!

    #250149 Reply

    laguiz
    Member

    Lol I’m sorry for spam …

    import javax.persistence.*;

    —>[- ]

    thanks Sebastian ^^

    #250250 Reply

    laguiz
    Member

    I can’t see my Bean in JNDI View

    I have look source but …

    Problems with XDoclet ?

    #250267 Reply

    Pat Osterday
    Member

    laguiz, check your jboss log file to make sure your deployment was successful – sometimes jboss problems don’t show up in the console window and you have to check the log. With ejb3, I’m pretty sure there is no need to run XDoclet.

    #250345 Reply

    laguiz
    Member

    I found the solution.

    Log file :

    16:02:33,393 INFO [Ejb3AnnotationHandler] found EJB3: ejbName=BookTestBean, class=de.laliluna.library.BookTestBean, type=STATELESS
    16:02:34,054 FATAL [PersistenceXmlLoader] FirstEjb3Tutorial JTA
    16:02:34,085 INFO [Ejb3Deployment] EJB3 deployment time took: 1258
    16:02:34,117 INFO [JmxKernelAbstraction] installing MBean: persistence.units:jar=FirstEJB3Tutorial.jar.jar,unitName=FirstEjb3Tutorial with dependencies:
    16:02:34,117 INFO [JmxKernelAbstraction] jboss.jca:name=DefaultDS,service=ManagedConnectionFactory
    16:02:34,447 INFO [Environment] Hibernate 3.1.2
    16:02:34,478 INFO [Environment] hibernate.properties not found
    16:02:34,494 INFO [Environment] using CGLIB reflection optimizer
    16:02:34,494 INFO [Environment] using JDK 1.4 java.sql.Timestamp handling
    16:02:35,296 INFO [Ejb3Configuration] found EJB3 Entity bean: de.laliluna.library.Book
    16:02:36,523 INFO [AnnotationBinder] Binding entity from annotated class: de.laliluna.library.Book
    16:02:36,822 INFO [EntityBinder] Bind entity de.laliluna.library.Book on table book
    16:02:37,923 INFO [ConnectionProviderFactory] Initializing connection provider: org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider
    16:02:37,939 INFO [InjectedDataSourceConnectionProvider] Using provided datasource
    16:02:37,939 INFO [SettingsFactory] RDBMS: MySQL, version: 4.1.9-nt
    16:02:37,939 INFO [SettingsFactory] JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-3.1.12 ( $Date: 2005-11-17 15:53:48 +0100 (Thu, 17 Nov 2005) $, $Revision$ )
    16:02:38,065 INFO [Dialect] Using dialect: org.hibernate.dialect.MySQLDialect
    16:02:38,112 INFO [TransactionFactoryFactory] Using default transaction strategy (direct JDBC transactions)
    16:02:38,159 INFO [TransactionManagerLookupFactory] instantiating TransactionManagerLookup: org.hibernate.transaction.JBossTransactionManagerLookup
    16:02:38,254 INFO [TransactionManagerLookupFactory] instantiated TransactionManagerLookup
    16:02:38,254 INFO [SettingsFactory] Automatic flush during beforeCompletion(): enabled
    16:02:38,254 INFO [SettingsFactory] Automatic session close at end of transaction: disabled
    16:02:38,254 INFO [SettingsFactory] JDBC batch size: 15
    16:02:38,254 INFO [SettingsFactory] JDBC batch updates for versioned data: disabled
    16:02:38,269 INFO [SettingsFactory] Scrollable result sets: enabled
    16:02:38,269 INFO [SettingsFactory] JDBC3 getGeneratedKeys(): enabled
    16:02:38,269 INFO [SettingsFactory] Connection release mode: after_statement
    16:02:38,269 INFO [SettingsFactory] Maximum outer join fetch depth: 2
    16:02:38,269 INFO [SettingsFactory] Default batch fetch size: 1
    16:02:38,269 INFO [SettingsFactory] Generate SQL with comments: disabled
    16:02:38,269 INFO [SettingsFactory] Order SQL updates by primary key: disabled
    16:02:38,269 INFO [SettingsFactory] Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
    16:02:38,301 INFO [ASTQueryTranslatorFactory] Using ASTQueryTranslatorFactory
    16:02:38,301 INFO [SettingsFactory] Query language substitutions: {}
    16:02:38,301 INFO [SettingsFactory] Second-level cache: enabled
    16:02:38,301 INFO [SettingsFactory] Query cache: disabled
    16:02:38,301 INFO [SettingsFactory] Cache provider: org.hibernate.cache.HashtableCacheProvider
    16:02:38,317 INFO [SettingsFactory] Optimize cache for minimal puts: disabled
    16:02:38,317 INFO [SettingsFactory] Structured second-level cache entries: disabled
    16:02:38,348 INFO [SettingsFactory] Statistics: disabled
    16:02:38,348 INFO [SettingsFactory] Deleted entity synthetic identifier rollback: disabled
    16:02:38,364 INFO [SettingsFactory] Default entity-mode: pojo
    16:02:38,553 INFO [SessionFactoryImpl] building session factory
    16:02:38,710 WARN [ServiceController] Problem starting service persistence.units:jar=FirstEJB3Tutorial.jar.jar,unitName=FirstEjb3Tutorial
    java.lang.reflect.InvocationTargetException
    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.jboss.ejb3.ServiceDelegateWrapper.startService(ServiceDelegateWrapper.java:97)
    at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
    at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
    at sun.reflect.GeneratedMethodAccessor22.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
    at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
    at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
    at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:260)
    at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
    at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:974)
    at $Proxy0.start(Unknown Source)
    at org.jboss.system.ServiceController.start(ServiceController.java:417)
    at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
    at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
    at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
    at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:260)
    at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
    at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:190)
    at $Proxy41.start(Unknown Source)
    at org.jboss.ejb3.JmxKernelAbstraction.install(JmxKernelAbstraction.java:76)
    at org.jboss.ejb3.Ejb3Deployment.startPersistenceUnits(Ejb3Deployment.java:599)
    at org.jboss.ejb3.Ejb3Deployment.start(Ejb3Deployment.java:452)
    at org.jboss.ejb3.Ejb3Module.startService(Ejb3Module.java:139)
    at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
    at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
    at sun.reflect.GeneratedMethodAccessor22.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
    at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
    at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
    at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:260)
    at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
    at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:974)
    at $Proxy0.start(Unknown Source)
    at org.jboss.system.ServiceController.start(ServiceController.java:417)
    at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
    at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
    at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
    at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:260)
    at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
    at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:190)
    at $Proxy28.start(Unknown Source)
    at org.jboss.ejb3.EJB3Deployer.start(EJB3Deployer.java:365)
    at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1007)
    at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:808)
    at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:771)
    at sun.reflect.GeneratedMethodAccessor15.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
    at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
    at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
    at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
    at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
    at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
    at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:260)
    at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
    at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:190)
    at $Proxy6.deploy(Unknown Source)
    at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:334)
    at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:522)
    at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.doScan(AbstractDeploymentScanner.java:207)
    at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.loop(AbstractDeploymentScanner.java:218)
    at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.run(AbstractDeploymentScanner.java:197)
    Caused by: org.hibernate.MappingException: could not instantiate id generator
    at org.hibernate.id.IdentifierGeneratorFactory.create(IdentifierGeneratorFactory.java:97)
    at org.hibernate.mapping.SimpleValue.createIdentifierGenerator(SimpleValue.java:152)
    at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:181)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1176)
    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:414)
    at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:575)
    at org.hibernate.ejb.Ejb3Configuration.createContainerEntityManagerFactory(Ejb3Configuration.java:245)
    at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:108)
    at org.jboss.ejb3.entity.PersistenceUnitDeployment.start(PersistenceUnitDeployment.java:260)
    … 77 more
    Caused by: org.hibernate.MappingException: Dialect does not support sequences
    at org.hibernate.dialect.Dialect.getSequenceNextValString(Dialect.java:528)
    at org.hibernate.id.SequenceGenerator.configure(SequenceGenerator.java:65)
    at org.hibernate.id.IdentifierGeneratorFactory.create(IdentifierGeneratorFactory.java:93)
    … 85 more
    16:02:38,914 INFO [JmxKernelAbstraction] installing MBean: jboss.j2ee:service=EJB3,jar=FirstEJB3Tutorial.jar,name=BookTestBean with dependencies:
    16:02:38,914 INFO [JmxKernelAbstraction] persistence.units:jar=FirstEJB3Tutorial.jar.jar,unitName=FirstEjb3Tutorial
    16:02:38,946 INFO [EJB3Deployer] Deployed: file:/C:/Program Files/jboss-4.0.4RC1/server/default/deploy/FirstEJB3Tutorial.jar
    16:02:38,946 ERROR [URLDeploymentScanner] Incomplete Deployment listing:

    — MBeans waiting for other MBeans —
    ObjectName: persistence.units:jar=FirstEJB3Tutorial.jar.jar,unitName=FirstEjb3Tutorial
    State: FAILED
    Reason: java.lang.reflect.InvocationTargetException
    I Depend On:
    jboss.jca:service=ManagedConnectionFactory,name=DefaultDS
    Depends On Me:
    jboss.j2ee:service=EJB3,jar=FirstEJB3Tutorial.jar,name=BookTestBean

    ObjectName: jboss.j2ee:service=EJB3,jar=FirstEJB3Tutorial.jar,name=BookTestBean
    State: NOTYETINSTALLED
    I Depend On:
    persistence.units:jar=FirstEJB3Tutorial.jar.jar,unitName=FirstEjb3Tutorial

    — MBEANS THAT ARE THE ROOT CAUSE OF THE PROBLEM —
    ObjectName: persistence.units:jar=FirstEJB3Tutorial.jar.jar,unitName=FirstEjb3Tutorial
    State: FAILED
    Reason: java.lang.reflect.InvocationTargetException
    I Depend On:
    jboss.jca:service=ManagedConnectionFactory,name=DefaultDS
    Depends On Me:
    jboss.j2ee:service=EJB3,jar=FirstEJB3Tutorial.jar,name=BookTestBean

    Problem in my class :

    
    ...
    @Entity
    @Table(name="book")
    @SequenceGenerator(name = "book_sequence", sequenceName = "book_id_seq")
    public class Book implements Serializable {
    ...
    

    Change :

    
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "book_sequence") 
    

    by

    
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "book_sequence")
    

    It’s ok now.

    I work with MySQL.
    Wy we can’t use GenerationType.SEQUENCE with MySQL (if probleme is MySQL) ?

Viewing 15 posts - 1 through 15 (of 37 total)
Reply To: EJB 3 Tutorial with JBoss

You must be logged in to post in the forum log in