• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Persisting new entity won't be persisted in jointable

 
Amir Al
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I'm having little bit problems with granting a new user access to my web application. Let me tell you my situation, problem and hopefully get some help from here .

Web Application
==========


I'm only telling this part of my web application since others doesn't have any other impact on it. So I have a web application where administrator can create a user, when this user is created he should be given USER level access. I have done security using GlassFish 3.1.2 by creating jdbcRealm which works perfectly and no problems occurred this far. My database is Derby and it have following tables:

- USER_PROFILE
- USER_GROUPS
- GROUPS

USER_PROFILE is table where is stored all users information, such as ID, first name, last name, username, password, etc. GROUPS is table where is stored all groups information such as ID, group name and group description. USER_GROUPS is a join table where is only username and group name columns. USER_PROFILE have ManyToOne relationship to GROUPS, meaning that GROUPS can have many users and GROUPS have OneToMany relationship to USER_PROFILE which also have @joinTable annotation.

Technologies Used
============


Following technologies are used in this part of web application:

- Java as language to program the whole stuff
- JPA to handle persisting and other DAO classes
- Hibernate to take care of mapping objects to database
- Derby as Database
- GlassFish 3.1.2 is used as server and also to implement jdbcRealm
- Servlets for business logic, meaning that there is persisted the new entity when information is available (e.g. setUserFirstName("myFirstName"))
- JSP to do all required pages

Code
====


The following classes codes are necessary to explore:

- UserProfile
- Groups
- Servlet code
- UserProfileDaoImpl()
- GroupsDaoImpl()

1. Note: EntityClass is just a super class that generates ID's automatically for each class that is extended with it and it works 100% fine. Thus I will not show it code here.
2. Note: All DaoImpl() classes have general JPA commands like persist(), remove(), merge(), findByPrimaryKey(), etc.

UserProfile:


Groups:


Servlet:


UserProfileDaoImpl():


GroupsDaoImpl():


Problem
=====


My problem is that whenever I persist a new user it won't be persisted in USER_GROUPS join table and this will cause "not access granted" to new user. What is the solution for this? Any help is really appreciated. User is persisted into USER_PROFILE and all its information are there 100% correct. Is this the best way to implement such thing? When groups entities with users are created first time they work well. In my web application I have same kind of implementation with ManyToMany relationship entities and they work 100%, no issues and no hassle. I'm just wondering why this can be so difficult with OneToMany relationship entities.

The Aim
=====


What I want from this is following:

1. Admin registers a user
2. User is persisted to USER_PROFILE table
3. User is persisted to USER_GROUPS join table by allocating already existing groups entities (USERS or ADMINS)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic