Company Blog
Home / Company Blog
While browsing a site on your iPhone (or iPod Touch) you can tap the plus icon and select ‘Add to Home Screen’. This creates a shortcut to that URL as an icon that you can delete and move around just like an app. The default icon for a webclip is to screengrab the current page, however you can specify your own icon.
What to do
Create your icon as a 57×57px PNG file and put it in a publicly accessible location on your server (you don’t need to create round corners the OS will do this for you). Then add the following code inside the head tags in your page:
<link rel="apple-touch-icon" href="[PATH_TO_ICON]/webclip.png" />
Now when you save your page as a webclip this will be the icon that’s used on your home screen. Additionally if you want to remove the effects added by the OS, namely 3D borders and reflective shine, use the following:
<link rel="apple-touch-icon-precomposed" href="${rc.contextPath}/assets/images/webclip.png" />
I was looking into the “single table per hierarchy” method of mapping inheritance with Hibernate and found out something new about how to declare the discriminator.
With a standard discriminator, you need a separate column in this method to tell Hibernate what type of object can be found in this row. In some cases it’s easy to have this extra column but in some cases you don’t have the control you would like over the structure of the data in the database.
If you can’t have a separate discriminator column, you can use the @DiscriminatorFormula annotation to pass in a sql fragment that Hibernate will use to determine the class of a particular row of data stored with this method.
See the Hibernate Annotations reference on inheritance for more information.
We run applications with Jetty during our development process and it’s useful to be able to link up a debugger while the application is running.
Since Jetty is launched from maven we need to do the following:
1. From your prompt run the following command to allow you to connect to the application remotely.
Post JDK1.3.x
export MAVEN_OPTS=”-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005″
Pre JDK1.3.x
export MAVEN_OPTS=”-Xnoagent -Djava.compiler=NONE -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005″
2. Go to IntelliJ and click on Run -> Edit Configurations. Then click on the + button followed by Remote to add a remote configuration. Make sure you are listening on the right port (5005) and click apply.
When you start Jetty from Maven you will see
Listening for transport dt_socket at address: 5005
Then you go into IntelliJ, choose the Remote configuration that you have just set up, and press debug. Now you can set breakpoints and debug the code.
Update 7th May: As it turns out, you can also run jetty using “mvnDebug jetty:run” which has the same effect. Just remember to choose the correct socket address in the IntelliJ configuration.
Coffee Rosters
One of the items that I’ve struggled to find documentation on is how to store a collection of enums with Hibernate Annotations.
Lets say for this example that we want to have an object called CoffeeRoster. The purpose of this object is to record what days a person will be responsible for buying coffee and snacky things for the office. And in this object we will store the person’s name and a set of days.
@Entity
public class CoffeeRoster{
@Id @GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@CollectionOfElements
@Enumerated(EnumType.STRING)
private Set<Day> buyingDays = new HashSet<Day>();
private String name;
//default no args constructor, getters and setters.
}
Taking a look at that example, we have an annotation for the fact that this is an entity and we note that we have a generated value id field.
At the bottom you’ll see that ‘name’ doesn’t have an annotation. This is because if you don’t explicitly declare an annotation, Hibernate will try to store it by itself. If we didn’t want name to be stored in the database, we’d have to use the @Transient annotation to declare it as transient.
So on to the important bit about the collections…
@CollectionOfElements
The correct way to store a collection is to use this annotation. In the background, a table is created for us that will be called CoffeeRoster_buyingDays which will have two columns, CoffeeRoster_id and element.
Then you’ll notice the @Enumerated(EnumType.STRING). If you try this example without this line, the ordinal of the enum is stored in the database, but if you use this annotation, the name of the enum is used instead.
For example, in our database we can see the following:
| CoffeeRoster_id |
element |
| 3 |
MONDAY |
| 3 |
WEDNESDAY |
| 3 |
FRIDAY |
It was also interesting to find that CollectionOfElements looks to be the way forward with mapping collections in general – (from Hibernate Annotations Reference Guide)
Previous versions of Hibernate Annotations used the @OneToMany to mark a collection of elements. Due to semantic inconsistencies, we’ve introduced the annotation @CollectionOfElements. Marking collections of elements the old way still work but is considered deprecated and is going to be unsupported in future releases.