Sunday, January 27, 2008

Petition to get better via drivers

There is a new petition to ask VIA to improve their linux driver here.
My take on that? It's a great initiative, but the best way to convince a company is to vote with your wallet. That shows companies that there is a potential market and will make them invest more in this market. So if you like linux, purchase a computer with linux-preloaded like dell offers. And if you want a double boot windows/linux, still purchase a linux preloaded laptop and purchase your windows copy on the side. The more people will purchase linux preloaded computers, the more companies will invest energy to make their hardware works well under linux, the more people will be attracted by the linux preloaded computers, the more......well, you got my point :-)

Tuesday, January 22, 2008

Dynamic faces not working in Netbeans 6.0 (Update: there is a fix available!)

There is a nasty bug in the woodstock components shipped with netbeans 6.0, that makes that dynamic faces just doesn't work. If like me, you enjoy refreshing parts of your JSF pages using AJAX, you will see that DynaFaces.fireAjaxTransction() makes your components disappear, instead of refreshing them. The bug has been reported here. So let's hope it gets fixed soon.

If you are just trying to refresh a simple component like a label, have a look at the woodstock documentation (Help->JavaDoc References->Project Woodstock 4.1 Tag Library). You will see that some components have a javascript refresh() method that can refresh them using AJAX.

Friday, January 18, 2008


JPA and JAXB both provide a way to annotate your java classes to tell how they should be serialized. JPA annotations defines how your class is mapped to the database, and JAXB annotations define how your class is serialized to XML. But is it possible to have both annotations on the same classe, to be able to convert your data from the database, to java object, then to XML or any combination of the 3?

Well yes it is, and it works pretty well :-)
Here is what your code will look like:


@Table(name = "car")

@NamedQueries({@NamedQuery(name = "Car.findByCarId", query = "SELECT c FROM Car c WHERE c.carId = :carId")})

public class Car implements Serializable {
private static final long serialVersionUID = 1L;


@Column(name = "car_id", nullable = false)

private Integer carId;
@Column(name = "brand")

private String brand;
@JoinColumn(name = "person_id", referencedColumnName = "person_id")

private Person personId;

public Car() {


public Car(Integer carId) {
this.carId = carId;


public Integer getCarId() {
return carId;


public void setCarId(Integer carId) {

this.carId = carId;

public String getBrand() {

return brand;

public void setBrand(String brand) {

this.brand = brand;

@XmlElement(name = "owner")

public Person getPersonId() {
return personId;


public void setPersonId(Person personId) {

this.personId = personId;

There are several things to notice about that:

1)The JPA annotations decorate the attributes where the JAXB annotations decorate the bean properties (...the getters if you want...)

2)There is a catch when you have bidirectional relationships. XML doesn't allow bidirectional relationships (You cannot have element A in element B and element B in element A :-)). So if you convert from XML to Java, then try to persist the object in your DB, you will see that something goes wrong. So just make sure that you restore those missing relationships in your java object (eg, if!=null, then car.owner shouldn't be null) and everything will work fine.

2 things to remember when using JPA

Java persistence API offers a great Object Relational Mapping framework to develop java application. In combination with a wizzard that auto-generates the entity classes from your databse, it makes an easy, clean, and quick way to store your data in a database. Unfortunately, some or the errors you can get with JPA are not always easy to debug. So here are the two lessons I learned while spending hours trying to debug my code:

1)If you have a bidirectionnal relationthip (annotated with a @mapped_by), it is your responsability to make sure that the two fields that reference each-other contain what they should. I say it again, it is YOUR responsability. And if it doesn't, and you try to persist your object, you will probably get a violation constraint in you database, without JPA telling you that you messed up.

2)If your table has a field table_id, which value is auto-generated by your database, make sure to annotate the mapping java field with @Id and @GeneratedValue(strategy="IDENTITY"). If you don't, everything will work fine when you just persist your table, but things won't work when persisting the table in cascade.

Wednesday, January 9, 2008

The FSF is looking for new members

The free software foundation is running a campaign to recruite new associate members.
The free software foundation is dedicated to promote user's right in the IT world. Some of the their most famous activities include the GPL license, the GNU project, freebios or gnash. They also have several campaign to eliminate DRMs, promote ODF or ogg and in general, point out freedom issues as they appear.

So if you want to participate or help encouraging all those good stuffs, consider joining in :-)