I'm sure this is a question in which the majority answer "Why are you doing this?", But I thought I will ask.
I have a table (user), most of which only have an ID (because they weaken users for those sessions who have never provided any information), and in the database Do not use the remaining columns. I have decided to remove these lines to save space in the database. The table has loads of tables with foreign keys, but only two or three can refer to these fake users.
For these tables I have switched the map to map userid instead of user object
, but would like to keep some objects in the entire user object, if it exists in the table Is, and otherwise is not empty.
Create user as table (userid bigint); Prepare the table as a shopping (cartridges, utensils, bilts);
I can not see how to map it to hibernate.
@Entity Class User {@Id long id; } @ Entity Class shoppingcart {@Id long id; @column ("user id") long user id; // can not be consistent with a user @ManyToOne (fetch = FetchType.LAZY) @JoinColumn ("userid", insertable = false, updateable = false, nullable = true) user user; }
Now, it does not return a blank, but throws a ObjectNotFoundException
, if user_id points to a user who does not exist. Even if you add @ (FetchMode.JOIN)
What is the procedure for treating it as null
?
I have considered some ways to do this:
- Add
-
LoadEventListener
, which will be any load ofuser
But gives special "empty objects", which can not be found (andPreInsert / PreUpdateEventListener
to save that vetos). -
ShoppingCart
to add a descriminator column and a subclass where theuser
is mapped, and one does not mapping that single table Is using succession. - (edit)
a lot of
collections ofusers
s, which will be an empty collection of cases where it does not exist, and In the second case, a collection with an ID - will this work be done without the table joining?
Any comments on these, or other ideas?
From the hibernate annotation reference, you can
@ManyToOne @NotF Ound (action = NotFoundAction.IGNORE)
Comments
Post a Comment