How to fix the Hibernate “object references an unsaved transient instance – save the transient instance before flushing” error

You should include cascade=”all” (if using xml) or cascade=CascadeType.ALL (if using annotations) on your collection mapping. This happens because you have a collection in your entity, and that collection has one or more items which are not present in the database. By specifying the above options you tell hibernate to save them to the database when saving their parent.

Java “user.dir” property – what exactly does it mean?

It’s the directory where java was run from, where you started the JVM. Does not have to be within the user’s home directory. It can be anywhere where the user has permission to run java. So if you cd into /somedir, then run your program, user.dir will be /somedir. A different property, user.home, refers to the user directory. As in /Users/myuser or /home/myuser or C:\Users\myuser. See here for a list of … Read more

Display Animated GIF

Android actually can decode and display animated GIFs, using android.graphics.Movie class. This is not too much documented, but is in SDK Reference. Moreover, it is used in Samples in ApiDemos in BitmapDecode example with some animated flag.

Creating a maze solving algorithm in Java

You probably should module your program – as I can understand it, you are reading the maze from file and trying to solve it at the same time. A better approach will be to split the program into 2 distinct parts: read the input file and create a matrix with all the data solve the maze from … Read more

Enqueue, Dequeue and ViewQueue in Java

Java queues don’t have enqueue and dequeue methods, these operations are done using the following methods: Enqueuing: add(e): throws exception if it fails to insert the object offer(e): returns false if it fails to insert the object Dequeuing: remove(): throws exception if the queue is empty poll(): returns null if the queue is empty Take … Read more

Immutable class?

What is an immutable object? An immutable object is one that will not change state after it is instantiated. How to make an object immutable? In general, an immutable object can be made by defining a class which does not have any of its members exposed, and does not have any setters. The following class … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)