Results 1 to 11 of 11
  1. #1
    wlad is offline Member
    Join Date
    Jul 2013
    Posts
    6
    Rep Power
    0

    Default What is some general route of EJB application developing process?

    Hello all,

    Question for those that have some EJB developing experience, that have developed some serious EJB applications, and understand EJB architecture well.

    What is some general developing order when starting new EJB project? What does need to be done first, what are your practices?

    I am familiar with developing desktop apps that communicate with DB, Servlets, JSP, MVC, databases, and now starting with distributed programming, concretely with EJB3.
    Now, I've just spent few weeks studying EJB3 concepts, and did some simple examples.

    I have an assignment to build a Blog application using EJB3 technology. Given are: object/class diagram, use-cases and software architecure.
    Requirements:
    - MySQL server for database
    - Eclipse IDE
    - Apache TomEE as web server&container
    - MVC pattern:
    model: JPA Entity
    view: HTML, CSS, JavaScript, JSP, EL и JSTL
    controller: Servlets
    - DAO - Session Beans
    - use 'log4j' framework for logging
    - use Ant build tool for building application

    Any help and comments are appreciated, (I do not expect from you to do my homework, just asking for simple advice).
    Thanks.

  2. #2
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,843
    Rep Power
    5

    Default Re: What is some general route of EJB application developing process?

    Those are not requirements, those are technical specifications. So far I don't see anything that would warrant actually using EJB technology, EJBs become useful when you want to do highly transactional applications. A blog is way too simple a thing to go as far as throw EJBs at it, so perhaps you want to pick a different project.

    Of course this doesn't mean that you can't use EJBs for the blog project, you'll just not see the point of EJBs at all because you won't use the tech for what it was designed. Its hard to give out any pointers when your project already does not fit the technology though.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    wlad is offline Member
    Join Date
    Jul 2013
    Posts
    6
    Rep Power
    0

    Default Re: What is some general route of EJB application developing process?

    Thanks for reply,
    I am aware that Blog application can be built simpler way, but this is a faculty project assignment. I have to use EJB3 specification, with tools and technologies mentioned above (not requirements, apologize for wrong expression).
    Anyway, as I said, I have a database, I have use cases scenarios, site maps. Just asking what are usual first steps when starting EJB developing process. Of course, creating a project in Eclipse is start, but which part to start implementing first? Should I start with coding entity beans that maps to DB entities, or should I start with session beans and bussines logic?

  4. #4
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,843
    Rep Power
    5

    Default Re: What is some general route of EJB application developing process?

    No difference from regular software development - start with the business logic, what EJB services you need will follow from that. They will likely be dumb DAO style EJBs which don't teach you anything about EJBs at all. You'll be mostly working with the JPA part of the JEE platform, very minimalistically also because a blog doesn't require much data transfer, just a few simple selects and some persists.

    Self advertisement: I wrote an article about EJBs which is well received by all that read it, perhaps that gives you an idea of what you'll be missing out on:

    Java Enterprise Stuff: EJB transactions: going deeper
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    wlad is offline Member
    Join Date
    Jul 2013
    Posts
    6
    Rep Power
    0

    Default Re: What is some general route of EJB application developing process?

    Your article on EJB transactions details, proves that working with EJB is your comfort zone! I am getting more familiar with EJB's every day, and really appreciate any advice and guide reference.
    Thanks again

  6. #6
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,843
    Rep Power
    5

    Default Re: What is some general route of EJB application developing process?

    I suggest you buy the book Enterprise Javabeans 3.1 (O'Reilly publishing) - its the best book on EJBs I know. If you're limited to using EJB 3.0 then perhaps you could pickup the Enterprise Javabeans 3.0 edition for a discount price, which is equally good but does not cover the new EJB 3.1 features of course.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  7. #7
    wlad is offline Member
    Join Date
    Jul 2013
    Posts
    6
    Rep Power
    0

    Default Re: What is some general route of EJB application developing process?

    Quote Originally Posted by gimbal2 View Post
    I suggest you buy the book Enterprise Javabeans 3.1 (O'Reilly publishing)
    Right now I am following book "EJB 3 Developer Guide (PACT Publishing)", and periodically "Mastering Enterprise JavaBeans 3.0 (Wiley Publishing)". I will look for your suggested book to get to know new features in EJB 3.1.

    I have just read chapters related to Entities, OR mapping, JPQL, Entity Manager and Transactions, and think I have understood JPA concepts, and proper use of annotations.
    From examples on entity beans, I got the idea how would I implement entity beans for my Blog application. But, I am not exactly sure how to approach to creating database.
    Let me explain my doubt:
    I have object/class diagram (it's what is given):
    What is some general route of EJB application developing process?-class-diagram.jpeg

    I have created ER model using MySQL Workbench, and would also know how to create simple DB models manually, using mysql terminal commands. But, if I've understood properly, JPA persistence engine is able to create database tables from implemented entity beans. Proper use of annotations carry all needed informations to create a database. Correct me if i'm wrong. So, my view of whole process is to be focused on proper way of annotating entity classes, and then there will be some "create database" command in ant build file during deployment phase. This way process of creating a database would alse be automated. Am i right?

  8. #8
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,843
    Rep Power
    5

    Default Re: What is some general route of EJB application developing process?

    Your question depends on the persistence provider you use. JPA is but an API, it doesn't do anything itself. If you use for example Hibernate as the persistence provider, it has an option to generate a database for you based on the entities, yes. The trick I use during development is to actually use an in-memory database (H2) so you don't even need a physical database yet and you can go wild making changes to the entities as you see fit; rebooting the application is all you need to have a freshly updated database. I create a class which is invoked during the startup of the server in which I persist the important data to the generated database. Because the in-memory database is generated at startup, whenever you restart the application you reset the data again. Very useful when you're starting out with the application.

    And now for the big trick: when it is time to hook up the real database, I do the following.

    - replace H2 with real database connection (say MySQL)
    - run application with automatic database generation on and let the initial data be created as per usual
    - shut down application
    - remove the call to the initial data creation
    - turn off automatic database generation

    And now there is a freshly created database already filled with relevant data, ready to go. No SQL scripting needed, although at this point it is recommended to use the DBMS tools to create an SQL dump of the database. I also wouldn't use JPA to push alters to the database, from this moment on I would do everything controlled with SQL scripts.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  9. #9
    wlad is offline Member
    Join Date
    Jul 2013
    Posts
    6
    Rep Power
    0

    Default Re: What is some general route of EJB application developing process?

    Thanks for such quick reply,
    Your advices are unveiling some hidden things i was passing by. I will consider your way of using in-memory DB during development, as soon as i get more comfortable with some basic things.
    Anyway, persistence provider that should be used is "Apache's OpenJPA persistence provider", probably because Apache's TomEE app server & container is also used. I mean it is not strictly required, I could also use JBoss AS, but from some other referential primer I have, those have been chosen.

    Previously, when i was developing desktop applications that communicate with DB, I would use some DB modeling tool for creating conceptual DB model, generate physical model, which is then used for generating DB creating script (SQL file). Run that script on live server and I would use jdbc api for accessing database from application.

    So, some basic straightforward way, when developing EJB app, is to generate DB tables, with all their relations, based on entities implementations?

  10. #10
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,843
    Rep Power
    5

    Default Re: What is some general route of EJB application developing process?

    You could stick to the default OpenJPA yes. Do note that each provider has its own quirks and I have always had the least troubles with Hibernate, plus I find it the best documented one. But when your entity model is simple and straightforward, any provider should work just fine.

    As for your last question - what you want to aim for is to save time. You don't want to be creating all the SQL scripts AND writing all the entities by hand, that's just double the effort and very error-prone. So you can do two things to save time:

    - create entities and let the database schema be generated from it once
    - create database schema and let the entities be reverse engineered from them

    The first option is a lot simpler, because then you get to do what I described to you earlier. It is also more likely that you can do it since most providers will have an option to do it, while generating entities is a less common feature. Of course Hibernate can do it through the hibernate tools ;)
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  11. #11
    wlad is offline Member
    Join Date
    Jul 2013
    Posts
    6
    Rep Power
    0

    Default Re: What is some general route of EJB application developing process?

    (After more than a month, I finally have time to continue working on this project. )
    Last two days, I have wrote code for entity classes according to given object model (model above). But, I'm not sure have i correctly mapped relationships between entities.
    If you look at the object model above, "Category" object unidirectionaly references itself - meaning that one category can have more subcategories.
    Also, "Category" object has one-to-many relationship with "Post" object (one category can have multiple posts).
    This is the part of the code, from Category entity that represents these relationships:

    Java Code:
    	
    @OneToMany(cascade = { ALL }, fetch = LAZY, mappedBy = "category")
       private Set<Post> posts = new HashSet<Post>();
    	
       public void add(Post p) {
    	if (p.getCategory() != null)
    		p.getCategory().getPosts().remove(p);
    	p.setCategory(this);
    	posts.add(p);
       }
    	
       public void remove(Post p) {
    	p.setCategory(null);
    	posts.remove(p);
       }
    
       @Column(name = "parent_category", unique = false, nullable = true)
       private Category parentCategory;
    	
       @OneToMany(cascade = { ALL }, fetch = LAZY, mappedBy = "parentCategory")
       private Set<Category> categories = new HashSet<Category>();
    	
       public void add(Category c) {
     	if (c.getParentCategory() != null)
     		c.getParentCategory().getCategories().remove(c);
    	c.setParentCategory(this);
    	categories.add(c);
       }
    	
       public void remove(Category c) {
    	c.setParentCategory(null);
    	categories.remove(c);
    }
    Getters and setters are basic, generated get/set methods for class attributes.
    I followed some other,referential example I have when I was writing these annotations.
    In similar way, I have annotated relationships between other objects in the model.
    Is this code proper for relationships between Category/ies, and Post?
    Last edited by wlad; 09-20-2013 at 07:01 AM. Reason: changed to [CODE] tags, instead of [QUOTE]]

Similar Threads

  1. developing chat application
    By niba10 in forum Networking
    Replies: 5
    Last Post: 06-29-2012, 12:04 AM
  2. Developing a Team collaboration/MIS web application
    By rudranee in forum Advanced Java
    Replies: 0
    Last Post: 05-03-2012, 08:02 AM
  3. developing a standalone application using java
    By santhoshkeleti in forum New To Java
    Replies: 1
    Last Post: 11-15-2011, 06:18 PM
  4. developing GUI application
    By earlhickey in forum New To Java
    Replies: 7
    Last Post: 06-22-2011, 03:14 AM
  5. Developing Window based application
    By hisouka in forum New To Java
    Replies: 7
    Last Post: 08-11-2008, 05:12 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •