JPA and @OneToMany – How to Optimize?

In this article I want to explain an issue concerning the JPA OneToMany relationship which I was faced with in one of my own projects. Working with object -orientated languages like java we often model relationships between object in various cases. One of such relationships is the OnToMany relationship. For example an object ‘Server’ may have a relationship to an object ‘Configuration’. To make the ‘Configuration’ object generic we can model the JPA object in Java like this:

@javax.persistence.Entity
public class Configuration implements java.io.Serializable {
 private static final long serialVersionUID = 1L;

 @Id
 @GeneratedValue
 private BigInteger id;

 public String itemValue;
 public String itemName;

 @SuppressWarnings("unused")
 private Configuration() {
 }

 public Configuration(String name, String value) {
 itemValue = value;
 itemName = name;
 }
}

Continue reading “JPA and @OneToMany – How to Optimize?”

GlassFish and PostgreSQL

To setup a PostgreSQL database connection in GlassFish is quite simple. There is one point which required special attention. First, it looks sufficient for the GlassFish DataPool configuration to only define the parameters “DatabaseName”, “User” and “Password”. By default, the URL has the value:

jdbc:postgresql://localhost/?loginTimeout=0&socketTimeout=0&prepareThreshold=5&unknownLength=2147483647&tcpKeepAlive=false&binaryTransfer=true&disableColumnSanitiser=false

But it is very important that the URL contains also the DatabaseName after the hostname:

jdbc:postgresql://localhost/[YOURDATABASENAME]?loginTimeout=0&socketTimeout=0&prepareThreshold=5&unknownLength=2147483647&tcpKeepAlive=false&binaryTransfer=true&disableColumnSanitiser=false

Otherwise it can happen that GlassFish losts the connection and is unable to find any tables. When you change your pool configuration don’t forget to restart GlassFish.

EclipseLink – DataSources!

If you configure postgresql in GlassFIsh or WildFly it seems to be very important that the additional property ‘url’ is always set with the corresponding jdbc connection url. Even if the setup wizzard (wildfly) did not fill this param!