1

I'm creating a JAVA EE project with JPA and JSF primefaces on a glassfish server.


Development environment is ECLIPSE IDE

Here is what I've done so far:

  • I Created the database in SQLServer (3tables, not that complicated structure)
  • I generated the entities from my table using JPA (eclipse offer this option...)

Here is what I want to do:

  • Generate the entity managers (session beans) for my entities so I can manage and create records in my database
  • finally I will create a UI using primefaces to display and edit and manage these records..

Question: Am I on the right path ? (conception level, or am I missing something out) + How to do my next step and that is generate the entity managers for my entities, Thanks in advance!

johnMcLean
  • 21
  • 2
  • I usually just use to eclipse to generate the entities and DAO's – Scary Wombat Jul 26 '16 at 08:39
  • entity managers u create them by your self ? that's kinda complicated to do..., also do you generate DAO's using hibernate ? – johnMcLean Jul 26 '16 at 08:42
  • 1
    When you generate everything, what exactly do you learn? – Gimby Jul 26 '16 at 08:43
  • @Gimby there is reason for looking on how to generate these things... I'm working on other projects, too bad i don't think that i've time to struggle with the creation of each session beans – johnMcLean Jul 26 '16 at 08:44

2 Answers2

0

Your approach looks simple and straight forward. Its alright. For proceeding further, this article can help you. http://www.informit.com/articles/article.aspx?p=1671224&seqNum=2

Please let me know if this helps.

Sirsendu
  • 283
  • 1
  • 8
  • it looks like a decent good example to understand how everything works to build an app.. I also noticed that he created the session bean and entity managers. So I think that confirm that I can't generate them. Thank you ! – johnMcLean Jul 26 '16 at 08:59
0

You're on the right path, but entity managers and session beans are not the same. You will use an EntityManager inside your session beans, like so:

@Stateless
public class MyService {

    @PersistenceContext
    private EntityManager em;
}

Make sure you have your persistence.xml file present. Further reading and examples can be found here.

Example persistence.xml file that uses a container managed datasource located through JNDI at jdbc/MyOrderDB:

<persistence>
    <persistence-unit name="OrderManagement">
        <jta-data-source>jdbc/MyOrderDB</jta-data-source>
    </persistence-unit>
</persistence>
Radu
  • 2,022
  • 3
  • 17
  • 28
  • understood, so I can't generate session beans, right ? i will just have to create them by my self – johnMcLean Jul 26 '16 at 08:56
  • Eclipse does have some templates for creating the EJBs, but as far as the methods in them you'll have to implement them depending on what functionality you need. – Radu Jul 26 '16 at 08:59
  • Yes, I can see that know... it just popped out to my mind that JAVA EE is like JAVA... IDEs can create a skeleton for you with the basic functionalities such as what crud does. unfortunately this is not the case – johnMcLean Jul 26 '16 at 09:03
  • CRUD has been abstracted in the `EntityManager`. For more complex queries I'd suggest looking at the `CriteriaQuery` API. – Radu Jul 26 '16 at 09:04