Saturday, March 28, 2015

JPA tips

JPA does not support any function to retrieve the database current date because it is not database portable. If you want to query the database date you can use a Native Query to get this value.

You cannot navigate inside a collection. You cannot do the following command: “department.memembers.name”. You can access a member's name using a command like: "select d from department d fetch join d.memembers m where m.name ='i88.ca' ".

The “SIZE” function will return the number of elements inside the collection.

You can add the “NOT” word in your queries. If you use the “IS EMPTY” you will search for a collection without values; if you use the “IS NOT EMPTY” you will search for a populated collection. The comparator “IS EMPTY” can be used to check a collection (e.g. @OneToMany) or a relationship class (e.g. @OneToOne). The “IS NULL” comparator cannot check a collection, but you can use it to check a non collection attribute (e.g. @OneToOne).

In/Any/Some/Exists has a close syntax. “Some” is an alias to “Any”.

The ALL operator will return true only if all items of the condition return true. A special case is that the list is empty then it still means all items of the condition is true and the comparator will return true . If this is not what you want then you may need to add a condition using "is not empty".

The “MEMBER OF” comparator will check if a given parameter belongs to a collection.

Popular Posts

Labels

ad ( 3 ) Amazon ( 47 ) Answer ( 1 ) API ( 25 ) automation ( 1 ) blog ( 23 ) book ( 2 ) career ( 12 ) cdn ( 2 ) centos ( 1 ) cloud ( 123 ) CRM ( 24 ) current ( 10 ) data ( 14 ) database ( 64 ) design patterns ( 14 ) development ( 3 ) eCommerce ( 25 ) email ( 94 ) ETL ( 2 ) framework ( 3 ) git ( 9 ) google ( 179 ) IDE ( 12 ) Integration ( 1 ) interview ( 15 ) Java ( 382 ) Java EE ( 105 ) javascript ( 43 ) Jboss ( 4 ) JPA ( 48 ) JSF ( 45 ) linux ( 338 ) Marketing ( 19 ) mobile ( 43 ) model ( 1 ) MySQL ( 198 ) online money ( 12 ) OOP ( 7 ) open source ( 25 ) performance ( 71 ) php ( 51 ) python ( 47 ) quality ( 5 ) referral ( 3 ) restful ( 23 ) security ( 126 ) SEO ( 18 ) social ( 26 ) software ( 72 ) spam ( 4 ) Spring ( 1 ) SQL ( 22 ) system ( 32 ) testing ( 17 ) tool ( 90 ) UML ( 8 ) virtual ( 10 ) web ( 223 ) web services ( 14 ) WildFly ( 4 ) wordpress ( 9 )