-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: How to: @JoinColumns to @JoinColumnsOrFormula for null vals?
PostPosted: Wed Sep 18, 2013 3:53 am 
Regular
Regular

Joined: Fri Feb 09, 2007 3:47 pm
Posts: 56
I saw this question on StackOverflow and it looked like it could use some loving, especially as I'm having a similar issue and the @JoinColumnsOrFormula documentation is a bit scarce. http://stackoverflow.com/questions/18825158/hibernate-how-to-move-from-joincolumns-to-joincolumnsorformulas-to-handle-nul

Quote:
I'm using Java and I'n having some issues with my hibernate mappings since all the tables use unique keys and not primary keys and I haven't managed to convince our DBA yet to add a PK column.

Currently I have the following:

Code:
@OneToMany
@JoinColumns({
@JoinColumn(name = "CITY", referencedColumnName = "CITY"),
@JoinColumn(name = "STREET", referencedColumnName = "STREET"),
@JoinColumn(name = "NUMBER", referencedColumnName = "NUMBER"),
@JoinColumn(name = "BUSNUMBER", referencedColumnName = "BUSNUMBER")})
private List<Address> addresses;

Now this works fine if all the fields are filled in, but I have some issues with the PersistentBag as soon as busnumber for the object is empty. After checking the Hibernate documentation I stumbled upon the @JoinColumnsOrFormulas annotation, but it's documentation seems a bit limited and even with a decent bit of googling I couldn't find any samples which actually join multiple columns as the name would imply.

is the way to go:

Code:
@OneToMany
    @JoinColumnsOrFormulas({
        @JoinColumnOrFormula(formula = @JoinFormula(value = "(SELECT a.CITY FROM A a WHERE a.CITY = CITY )", referencedColumnName = "CITY ")),
        @JoinColumnOrFormula(formula = @JoinFormula(value = "(SELECT a.STREET FROM A a WHERE a.STREET = STREET)", referencedColumnName = "STREET")),
        @JoinColumnOrFormula(formula = @JoinFormula(value = "(SELECT a.NUMBERFROM A a WHERE a.NUMBER = NUMBER)", referencedColumnName = "NUMBER")),
        @JoinColumnOrFormula(formula = @JoinFormula(value = "(SELECT a.BUSNUMBER FROM A a WHERE a.BUSNUMBER = BUSNUMBER or (a.BUSNUMBER is null AND BUSNUMBER is null))", referencedColumnName = "BUSNUMBER"))}
private List<Address> addresses;

or should I put it in a single @JoinFormula? I have currently written the above, but I can't test it yet as a reload is occurring on our DB.

edit: I have tried the above, but it seems that is note the correct way to go as I just got exceptions. Any advice is welcome.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.