lately I was testing HbnContainer and for now its running great. But I have one question:
Database structure is: ID (INT), CCC (VARCHAR), BBB(VARCHAR)
Data is loaded through Hibernate Container into a table with columns: BBB | CCC <— automatically in alphabetic order
What I need is: CCC | BBB <— like strukture in Database
java.lang.IllegalArgumentException: Ids must exist in the Container or as a generated column , missing id: firstName
com.vaadin.ui.Table.setVisibleColumns(Table.java:486)
com.example.kontak.KontakApp.createContent(KontakApp.java:67)
com.example.kontak.KontakApp.buildMainWindow(KontakApp.java:52)
com.example.kontak.KontakApp.init(KontakApp.java:43)
com.vaadin.Application.start(Application.java:554)
com.vaadin.terminal.gwt.server.AbstractApplicationServlet.startApplication(AbstractApplicationServlet.java:1208)
com.vaadin.terminal.gwt.server.AbstractApplicationServlet.service(AbstractApplicationServlet.java:484)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
if I remove the last 2 lines, my code works perfectly.
Here is my pojo class:
package com.example.kontak.domain;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity
public class Kontak implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String firstName = "", lastName = "";
private String phone = "";
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
}
Set the data source before setting the visible columns - or even better, in the same operation with setContainerDataSource(container, visibleColumns). Then call setColumnHeaders() after that operation.
Hello guys,
I’m experimenting the same issue while adding a HbnContainer to a table (I’m using Hibernate 4.0.1, Vaadin 6.7.1 and HbnContainer 1.1.0).
I’m not able to add the “id” property of my entity as a visible column.
This is a fragment of my entity:
@Entity
@DynamicUpdate
@Table(name = "asociados", uniqueConstraints={@UniqueConstraint(columnNames="dni")})
public class Asociado extends AbstractEntity<Long> {
@Id
@GeneratedValue
private Long id;
//Other properties here
@Override
public Long getId() {
return id;
}
//Other methods here
}
Note: AbstractEntity is not a @MappedSuperclass, it just contain a generic equals/hashCode based on the getId method that all its concrete subclasses must implement
I was taking a look at the code and I found this in the HbnContainer class:
public Collection<String> getSortableContainerPropertyIds()
{
// use Hibernates metadata helper to determine property names
String[] propertyNames = classMetadata.getPropertyNames();
LinkedList<String> propertyIds = new LinkedList<String>();
propertyIds.addAll(Arrays.asList(propertyNames));
propertyIds.addAll(getEmbeddedKeyPropertyIds());
return propertyIds;
}
The issue seems that the method call classMetadata.getPropertyNames() does not returns the identifier property name and there is no call to classMetadata.getIdentifierProperty() (which is the right method to get the Id property). getEmbeddedKeyPropertyIds() method does not return the id property name since my id is not an embedded key. classMetadata attribute is an instance of SingleTableEntityPersister. The method HbnContainer.getSortableContainerPropertyIds() is called by HbnContainer.getContainerPropertyIds() which is called by Table.getContainerPropertyIds() which is finally called by Table.setVisibleColumns(Object[] visibleColumns) to determine if the column provided by the client code exists.
Can you please add a fix?
As a workaround I have created a class that extends HbnContainer and wrote a method that overrides the getSortableContainerPropertyIds() that adds the call to ClassMetadata.getIdentifierPropertyName().
You should contact the developers of the add-on. If it is
this add-on , then there is a issue tracker link on the page which would be the optimal place.