• Post Reply Bookmark Topic Watch Topic
  • New Topic

What to do when EJB-QL is not enough

 
Tony Walters
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All

I'm in the middle of building an application using EJB and Struts. The problem I am having is with EJB-QL. I need some fairly complex queries and EJB-QL just doesn't appear up to the job.

I remember reading about an EJB design pattern for performing read-only queries using a session bean and JDBC (I think), and am wondering if this is a possible solution. I have relied heavily on design patterns up until now, and want to justify my solution to this particular problem in relation to tried and tested design patterns.

Is there anybody that knows of such a pattern, or something similar, to solve this problem. Any links to explanations would also be helpful.

Thanks in advance.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The quickest way round this is usually to use proprietory extension to EJB-QL provided by your container. Not a platform independant solution, but then neither are Entity Beans really. Entity bean patterns are very often anti-patterns given they often exist to correct issues which can be avoided by not using Entoty Beans in the first place!
 
Marcos Maia
Ranch Hand
Posts: 977
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

consider building a DAO. take a look at:

http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html
 
Tony Walters
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The system cannot (as yet) be tied to a particular application server, so a pure, non-proprietory J2EE solution is needed.

As for the DAO pattern, I can see how it would help abstract the underlying database, but I don't think that actually addresses the problem I'm having.

Basically, I need to issue complex read queries separately from update (create, update, delete) queries. I'm wondering whether to do these in a Session bean using JDBC, or perhaps using JSTL from the JSP page itself.
 
Tony Walters
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe this question would be better asked in the OO, Paterns, and UML forum. Am I allowed to ask it there, or does that count as cross-posting?
 
Alex Sharkoff
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tony,

In our project we use Session Beans to perform complex queries (directly through JDBC). The results of such queries are then stored in appropriate data objects (one per record returned), which are eventually returned to the servlet side.

Such approach allows us to have our business logic encapsulated on the model side (we use MVC principle: View - velocity, Controller - servlet, Model - EJBs). In addition, it is completely database independant (no proprietory EJB-QL is used)

Hope it helps to clarify the issue


[ December 02, 2004: Message edited by: Alex Sharkoff ]
 
Karthik Guru
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Alex Sharkoff:
Tony,

we use MVC principle: View - velocity, Controller - servlet,
[ December 02, 2004: Message edited by: Alex Sharkoff ]


Alex,

Why did you guys pick velocity over jsp? and was the controller actually struts?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Basically, I need to issue complex read queries separately from update (create, update, delete) queries. I'm wondering whether to do these in a Session bean using JDBC, or perhaps using JSTL from the JSP page itself

Doing this directly through JDBC makes sense. EJB-QL has always been a subset of SQL. Of course you will introduce DB platform-specific dependencies - e.g. if you ever require the DB to supply a time.

If its just for complex reads, have you considers views? Or alternatively putting these complex (possibly DB specific) queries into files and reading them in like a ResourceBundle? i.e. use a DAO layer which looks up queries from queries_MSSQL.sql, or queries_ORACLE.sql etc. ?

I know both of these imposes more DB specific work, but it would keep your Java code platform independant.

Best fit for your problem though really is to consider a better ORM technology than Entity Beans.
 
Alex Sharkoff
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Karthik,

Why did you guys pick velocity over jsp?


Well, we found velocity is much easier to learn (one just needs html skills plus going through the velocity how-to). In addition, there is no danger that java code will end up embedded into the html page.
At the same time I do recognise that jsp is a part of J2EE spec and therefore, it is widely used.


and was the controller actually struts?

We use our own mechanism (one servlet that acts as a request dispatcher, similar to struts; at the time of designing our app struts framework was still in the initial phase)


[ December 05, 2004: Message edited by: Alex Sharkoff ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!