Tuesday, April 22, 2014

Ways of Inheritance in Hibernate

Here is a great article for hibernate inheritance.

An example  of each of them is added. Advantages and disadvantages also are mentioned.

Using Subversion in Netbeans - solutions for all issues

Some mandatory steps needed after Netbeans installation to get SVN working.

0. Start position: svn functionality is not working. Item "Show annotations" in Team menu is deactivated.

1. Your subversion client version must match requirements by Netbeans. They are different for every Netbeans version. So check link - http://wiki.netbeans.org/FaqSubversionClients

2. Show annotations menu item in Team menu is active now.

3. Navigate menus: Tools > Options > Team -> Versioning > Subversion . Select "Path to the SVN executable file". It is placed in folder C:\Program Files\TortoiseSVN\bin by default. If executable could not be selected, may not be installed in SVN installation. Ensure "command line utils" checkbox is selected in the reinstallation.

4. Update or any SVN action could cause "sslprotocolexception: handshake alert:  unrecognized_name" in Netbeans. This is caused by missing configuration in Netbeans.
Solution:
Copy folders named: svn.ssl.client-passphrase, svn.ssl.server, svn.username
from folder: C:\Documents and Settings\<username>\Application Data\Subversion\auth
to folder: C:\Documents and Settings\<username>\AppData\Roaming\NetBeans\8.0\config\svn\config\auth

5. Finally solved! So enjoy your SVN client.

Spring repositories with native queries - Supported keywords inside findBy method names



KeywordSampleJPQL snippet
AndfindByLastnameAndFirstname… where x.lastname = ?1 and x.firstname = ?2
OrfindByLastnameOrFirstname… where x.lastname = ?1 or x.firstname = ?2
BetweenfindByStartDateBetween… where x.startDate between 1? and ?2
LessThanfindByAgeLessThan… where x.age < ?1
GreaterThanfindByAgeGreaterThan… where x.age > ?1
After
findByStartDateAfter… where x.startDate > ?1
Before
findByStartDateBefore… where x.startDate < ?1
IsNullfindByAgeIsNull… where x.age is null
IsNotNull,NotNullfindByAge(Is)NotNull… where x.age not null
LikefindByFirstnameLike… where x.firstname like ?1
NotLikefindByFirstnameNotLike… where x.firstname not like ?1
StartingWithfindByFirstnameStartingWith… where x.firstname like ?1 (parameter bound with appended %)
EndingWithfindByFirstnameEndingWith… where x.firstname like ?1 (parameter bound with prepended %)
ContainingfindByFirstnameContaining… where x.firstname like ?1 (parameter bound wrapped in %)
OrderByfindByAgeOrderByLastnameDesc… where x.age = ?1 order by x.lastname desc
NotfindByLastnameNot… where x.lastname <> ?1
InfindByAgeIn(Collection<Age> ages)… where x.age in ?1
NotInfindByAgeNotIn(Collection<Age> age)… where x.age not in ?1
TruefindByActiveTrue()… where x.active = true
FalsefindByActiveFalse()… where x.active = false


Source: http://docs.spring.io/spring-data/jpa/docs/1.4.3.RELEASE/reference/html/jpa.repositories.html

Wednesday, April 16, 2014

java syntax for catching multiple exceptions

New java syntax for catching multiple exceptions in a single section:

    try {
        // do something
    } catch (ImageProcessingException | IOException ex) {
        log.error("Unable to get orientation from file " + imagePath.toString(), ex);
    }




Friday, April 4, 2014

Skipping constraint checks in MySQL

Error
Cannot delete or update a parent row: a foreign key constraint fails

Issue:
mysql> update User SET id=6 where id = 8;

ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails (`database_name`.`table_name`, CONSTRAINT `FK_35jtu0049tkg8m9twhc03ii9` FOREIGN KEY (`customer`) REFERENCES `user` (`id`))

Solution:
SET foreign_key_checks = 1;
; execute code with constraint restrictions here
SET foreign_key_checks = 0;


Hibernate: setting foreigh key without getting foreign object

A nice solution from stackoverflow:
http://stackoverflow.com/questions/21012293/hibernate-add-entity-with-child-entity-id