0

I am following this tutorial i found http://www.vitruvimente.be/?p=768 to create a JDBC realm, so i can login and out my users on my web app, but i have a problem.

But i have 3 different types of users in different classes(Admin,Buyer,Seller) I dont have a single class called users because their attributes are very unrelated. I see in the tutorial they add a property called user-table, whay should i add there?

My question, is what settings should i add at the glassfish new realm page(localhost:4848)? Can somebody give me some tips on how to configure this realm?

javing
  • 12,307
  • 35
  • 138
  • 211

2 Answers2

3

i have 3 different types of users in different classes(Admin,Buyer,Seller) I dont have a single class called users because their attributes are very unrelated.

There's something wrong in your model design. You should really have a single table User with at least the login name and password. For the more specific user roles, you need a table Role. To relate them to each other, have a join table User_Role (which you map in Java as a Set<Role> in User entity). For the buyer/seller part it makes sense to have a Product table with a FK to User (the seller) and an Order table with a FK to User (the buyer) and Product (the ordered item).

After all, you should end up with a single User table/model which you could then just map in the realm.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • I did that i created the new JoinColum, the application works correcty and i am ready to start preparing the realm, but i found a few difficulties in the configuration. I created a new question: http://stackoverflow.com/questions/5620561/creating-my-first-jdbc-realmglassfish-v3 Could you guys give me a little hand? – javing Apr 11 '11 at 11:26
  • But to use a join table in GlassFish, one needs to use some database view to make GlassFish understand that database structure, right? (Without such view, GlassFish expects a one-to-many relationship from some `T_USER` table to some `T_ROLE` (or `T_GROUP` in GlassFish-speak), based on values in a [user-name-column](http://docs.oracle.com/cd/E19226-01/820-7701/6nium5vr2/index.html) present in both tables, right?) – Arjan Jan 16 '12 at 12:40
  • (As an aside: when mapping some tables `T_USER`, `T_USER_ROLES` and `T_ROLE` to GlassFish, one could of course make sure that `T_USER_ROLES` holds the String values that `@RolesAllowed` et al use, hence making GlassFish oblivious about table `T_ROLE`; see [GlassFish JDBC Realm Group Membership](http://stackoverflow.com/questions/6809081/glassfish-jdbc-realm-group-membership/6809340#6809340).) – Arjan Jan 16 '12 at 14:25
1

If you have changed your model as suggested by BalusC, I would recommend this good tutorial here for setting up a JDBC realm with glassfish.

Matt Handy
  • 29,855
  • 2
  • 89
  • 112