• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Issue in Model design

 
Naveen Kumar Idss
Greenhorn
Posts: 3
Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 3930
21
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some of your points are not clear to me, it might help if you can explain this with some pieces of sample code?
 
Naveen Kumar Idss
Greenhorn
Posts: 3
Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic