Solution : [org.springframework.beans.InvalidPropertyException: Invalid property 'id' of bean class Getter for property 'id' threw exception; nested exception is java.lang.reflect.InvocationTargetException] with root cause org.hibernate.LazyInitializationException: could not initialize proxy - no Session

Links to this post
This issue is because of whenever you call getEntityById(), once you retrieve the object the session will be closed.

So we need to re-atatched the session. You can do it by calling session.update(object).

But the easiest way is just configure entity.hbm.xml with lazy=false. If you are using annotations, just use @Proxy(lazy=false) on the entity class.
Advantage : Easy to use.
Disadvantage : It causes slow performance, because dependent objects will be loaded at the time persistence object is loading, which increase loading time of dependent objects and also
the object is fully initialized, so the memory consumption is high.

The best solution for this issue is invoking session.update(object)


Links to this post
The table containing the foreign key is called the referencing or child table, and the table containing the candidate key is called the referenced or parent table.
SET NULL : Sets the column value to NULL when you delete the parent table row. 
CASCADE : CASCADE will propagate the change when the parent changes. If you delete a row, rows in constrained tables that reference that row will also be deleted, etc. 
RESTRICT : RESTRICT causes you can not delete a given parent row if a child row exists that references the value for that parent row. 

NO ACTION : NO ACTION and RESTRICT are very much alike. when an UPDATE or DELETE statement is executed on the referenced table, the DBMS verifies at the end of the statement execution that none of the referential relationships are violated. in short child row no concern if parent row delete or update.

Resolved Error: javax.persistence.JoinColumn.foreignKey()Ljavax/persistence/ForeignKey

Links to this post
Error: "javax.persistence.JoinColumn.foreignKey()Ljavax/persistence/ForeignKey"

I was  trying to implement Hibernate Search functionality on my current project. I faced the above issue and resolved it with some research.

Root cause: 
 JoinColumn.foreignKey() was introduced with JPA 2.1, which was not implemented by Hibernate 4 until version 4.3. If you're using an older version of Hibernate 4, you will face this issue. Try to upgrade it to hibernate-jpa-2.1-api  and also Hibernate to 4.3.x.

If you're already using Hibernate 4.3 then make sure you're also using hibernate-jpa-2.1-api to make sure the API and implementation match up.

Resolved: “org.hibernate.ObjectNotFoundException: No row with the given identifier exists” but it does exists

Links to this post
Error: “org.hibernate.ObjectNotFoundException: No row with the given identifier exists” but it does exists.

I was facing this issue with my current project. There might be 2 possible reasons to occur this error.

Root Causes:
1. Whene there is relationship between two tables in the database, the main entity may not exists in the database, You can check it with session.get() method whether it is there or not.

2. There will be broken relationships. When entity X owns a relation with entity Y, when entity B is deleted while the Foreign Key(FK) in entity X is left untouched. So whenever Hibernate tries to load the link X->Y this error occurs.

My application root cause is 2. What is yours???



Links to this post
  • REST, RPC - architecture patterns, AMQP - wire-level and HTTP - application protocol which run on top of TCP/IP
  • AMQP is a specific protocol when HTTP - general-purpose protocol, thus, HTTP has damn high overhead comparing to AMQP
  • AMQP nature is asynchronous where HTTP nature is synchronous
  • Both REST and RPC use data serialization, which format is up to you and it depends of infrastructure. If you are using python everywhere I think you can use python native serialization - pickle which should be faster than JSON or any other formats.
  • Both HTTP+REST and AMQP+RPC can run in heterogeneous and/or distributed environment
So if you are choosing what to use: 
HTTP+REST or AMQP+RPC, the answer is really subject of infrastructure complexity and resource usage. Without any specific requirements both solution will work fine, but i would rather make some abstraction to be able switch between them transparently.
You told that your team familiar with HTTP but not with AMQP. If development time is an important time you got an answer.
If you want to build HA infrastructure with minimal complexity I guess AMQP protocol is what you want.
I had an experience with both of them and advantages of RESTful services are:
  • they well-mapped on web interface
  • people are familiar with them
  • easy to debug (due to general purpose of HTTP)
  • easy provide API to third-party services.
Advantages of AMQP-based solution:
  • damn fast
  • flexible
  • easy to maintain
  • easy to scale
  • cost-effective (in resources usage meaning)
Note, that you can provide RESTful API to third-party services on top of your AMQP-based API while REST is not a protocol but rather paradigm, but you should think about it building your AQMP RPC api. I have done it in this way to provide API to external third-party services and provide access to API on those part of infrastructure which run on old codebase or where it is not possible to add AMQP support.
If I am right your question is about how to better organize communication between different parts of your software, not how to provide an API to end-users.
If you have a high-load project RabbitMQ is damn good piece of software and you can easily add any number of workers which run on different machines. Also it has mirroring and clustering out of the box. And one more thing, RabbitMQ is build on top of Erlang OTP, which is high-reliable,stable platform ... (bla-bla-bla), it is good not only for marketing but for engineers too. I had an issue with RabbitMQ only once when nginx logs took all disc space on the same partition where RabbitMQ run.