When and why JPA entities should implement the Serializable interface?

The question is in the title. Below I just described some of my thoughts and findings. When I had a very simple domain model (3 tables without any relations), all my entities did NOT implement the Serializable interface. But when the domain model became more complex, I got a RuntimeException, saying that one of my … Read more

Doctrine – How to print out the real sql, not just the prepared statement?

We’re using Doctrine, a PHP ORM. I am creating a query like this: $q = Doctrine_Query::create()->select(‘id’)->from(‘MyTable’); and then in the function I’m adding in various where clauses and things as appropriate, like this $q->where(‘normalisedname = ? OR name = ?’, array($string, $originalString)); Later on, before execute()-ing that query object, I want to print out the … Read more

Difference Between One-to-Many, Many-to-One and Many-to-Many?

Ok so this is probably a trivial question but I’m having trouble visualizing and understanding the differences and when to use each. I’m also a little unclear as to how concepts like uni-directional and bi-directional mappings affect the one-to-many/many-to-many relationships. I’m using Hibernate right now so any explanation that’s ORM related will be helpful. As … Read more

How to persist a property of type List in JPA?

What is the smartest way to get an entity with a field of type List persisted? Command.java package persistlistofstring; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import javax.persistence.Basic; import javax.persistence.Entity; import javax.persistence.EntityManager; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Persistence; @Entity public class Command implements Serializable { @Id @GeneratedValue(strategy = GenerationType.AUTO) Long id; @Basic List<String> arguments … Read more

How to query between two dates using Laravel and Eloquent?

I’m trying to create a report page that shows reports from a specific date to a specific date. Here’s my current code: $now = date(‘Y-m-d’); $reservations = Reservation::where(‘reservation_from’, $now)->get(); What this does in plain SQL is select * from table where reservation_from = $now. I have this query here but I don’t know how to … Read more

SQLAlchemy: engine, connection and session difference

I use SQLAlchemy and there are at least three entities: engine, session and connection, which have execute method, so if I e.g. want to select all records from table I can do this engine.execute(select([table])).fetchall() and this connection.execute(select([table])).fetchall() and even this session.execute(select([table])).fetchall() – the results will be the same. As I understand it, if someone uses … Read more

Map enum in JPA with fixed values?

I’m looking for the different ways to map an enum using JPA. I especially want to set the integer value of each enum entry and to save only the integer value. @Entity @Table(name = “AUTHORITY_”) public class Authority implements Serializable { public enum Right { READ(100), WRITE(200), EDITOR (300); private int value; Right(int value) { … Read more