JavaRanch » Java Forums »
Java »
Object Relational Mapping
| Author |
Issue in Model design
|
Naveen Kumar Idss
Greenhorn
Joined: Jan 28, 2012
Posts: 2
|
|
Hi,
I am a starter when it comes to Java, I started with a ecommerce site but facing design issues. It is as follows :
1) I have created JPA entities for the tables in the database with mappings.
2) Created an interface called as service which has
Create(--) - adds data | Update(--) - updates data | Find(--),findal(--) - search data l delete(--) - deletes data
runQuery(--) - runs the query and returns the 'Query' (jpql)
executeQuery(--) - executes query (jpql)
3) Then created the service implementations for the tables accesing the entites created for tables.
4) After this I created Model where it does the CRUD operations with the services, using service interface.
5) The reason I did like this is I wanted the model to be portable to other ORM (Ex : Hibernate or other)
6) There are few cases where I need a method other than these like verifyAdmin(-) to verify administrator in administrator model;
7) I am able to write this method in the Administrator model, but the query results Objects, so I have to again import the entity, service into Administrator model. Which I do not want to do.
8) So it is clear that I cannot have a single interface Interface or abstract class for the services as each model may have different methods based on the requirement. ex : verifying user.
9) I feel following to be solutions :
a) Define interface for each of the service that corresponds to each entity.
b) Find a way that the Jpql gives a result set that I can type cast to string, int or float, without importing the service classes into model.
It would be a great help if any suggestions are provided, I am ready to re write the whole thing if the structure is wrong.
|
 |
Vijitha Kumara
Bartender
Joined: Mar 24, 2008
Posts: 3563
|
|
|
Some of your points are not clear to me, it might help if you can explain this with some pieces of sample code?
|
SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
|
 |
Naveen Kumar Idss
Greenhorn
Joined: Jan 28, 2012
Posts: 2
|
|
Sure,
Lets take one instance EX : administrator
table :
Entity : in jpa_entity package
Service Interface in ServiceInterface package
This is the Administrator service that implements interface
Model of Administrator
now in verifyAdmin(String user,String pass) method I have to initiate SAdministrator, because it has a method that is not in interface, the further change I am thinking is to make an abstract class implementing the service
interface so I can implement
which are common.
So, as we can see in the model I only want to have the interface or abstract imported....
|
 |
 |
|
|
subject: Issue in Model design
|
|
|
|