Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Is the use of @Column annotation as substitute of hibernate @Formula is possible?(hibernate formula)
icon3.gif  Is the use of @Column annotation as substitute of hibernate @Formula is possible? [message #933084] Thu, 04 October 2012 18:14 Go to next message
Dariusz Skrudlik is currently offline Dariusz SkrudlikFriend
Messages: 4
Registered: July 2009
Junior Member
I found that can use @Column annotation for execute subselect,
e.g


    private BigDecimal quantityOrders;

    @Column(name="(select 2 from dual) as quantityOrders",insertable = false, updatable = false)
    public BigDecimal getQuantityOrders() {
        return quantityOrders;
    }


I tested name with some select and all working. I can link to current table by name and all other in database. It is fantastic, but is it right ?

Where can I find any documentation for that ?

P.S.
In hibernate @Formula I can use 'this' for pointing current table, how do this here (it is important when define other alias e.g. when use CriteriaBuilder)







Re: Is the use of @Column annotation as substitute of hibernate @Formula is possible? [message #939166 is a reply to message #933084] Wed, 10 October 2012 13:39 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

EclipseLink does not currently have an equivalent to Hibernate's @Formula, please log a bug, and vote for it.

Setting the column name will work for simple queries, but not for complex queries.

The best solution is to create a view that adds the computed column to the table, and map the entity to the view.

You could also instead execute a named query for the value.

EclipseLink does have an @AttributeTransformer feature, that would allow you to execute a query for computed value.


James : Wiki : Book : Blog : Twitter
Re: Is the use of @Column annotation as substitute of hibernate @Formula is possible? [message #939388 is a reply to message #939166] Wed, 10 October 2012 18:14 Go to previous messageGo to next message
Dariusz Skrudlik is currently offline Dariusz SkrudlikFriend
Messages: 4
Registered: July 2009
Junior Member
I checked and name work even for multi table subselect (only when you don't use aliases).

If I use a view in database, will I be able to update data ?

Can you give me a example of usage @AttributeTransformer for subselect ? (I found only some java doc for that annotation).



Re: Is the use of @Column annotation as substitute of hibernate @Formula is possible? [message #946818 is a reply to message #939388] Tue, 16 October 2012 14:35 Go to previous message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Many databases allow updating simple views, for complex views you can use instead-of triggers to update them.

James : Wiki : Book : Blog : Twitter
Previous Topic:@Id and @AttributeOverride
Next Topic:using eclipselink in Eclipse' Tomcat
Goto Forum:
  


Current Time: Mon Dec 22 22:44:38 GMT 2014

Powered by FUDForum. Page generated in 0.01604 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software