JPAContainerFactory doesn't find all bean properties

Hi,

I’m new to Vaadin and JPAContainer, so hopefully this will be resolved with a quick configuration fix!

I’m using hibernate for persistence and have JPA annotated bean classes representing mysql DB tables and relationships. The bean classes work fine with another (non-Vaadin) project that is using them, and they were generated off of the tables using JBoss Tools’ reverse engineer Hibernate Code Generation tool.

Basically within the bean there are a handful of variables with the necessary getter and setter methods, including those for 2 boolean variables. Well, actually since they are boolean, the booleans have is_() methods instead of get_().


@Entity
@Table(name = "available", catalog = "mediaplayground")
public class Available implements java.io.Serializable {

	private Long availabilityId;
	private Date dateAvailable;
	private Date dateexpires;
	private boolean visible;
	private boolean deleted;
	private String note;
	private Set<Property> properties = new HashSet<Property>(0);
	private Set<Channel> channels = new HashSet<Channel>(0);
	private Set<Media> medias = new HashSet<Media>(0);

	public Available() {
	}

	public Available(Date dateAvailable, Date dateexpires, boolean visible,
			boolean deleted) {
		this.dateAvailable = dateAvailable;
		this.dateexpires = dateexpires;
		this.visible = visible;
		this.deleted = deleted;
	}

	public Available(Date dateAvailable, Date dateexpires, boolean visible,
			boolean deleted, String note, Set<Property> properties,
			Set<Channel> channels, Set<Media> medias) {
		this.dateAvailable = dateAvailable;
		this.dateexpires = dateexpires;
		this.visible = visible;
		this.deleted = deleted;
		this.note = note;
		this.properties = properties;
		this.channels = channels;
		this.medias = medias;
	}

	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "availabilityId", unique = true, nullable = false)
	public Long getAvailabilityId() {
		return this.availabilityId;
	}

	public void setAvailabilityId(Long availabilityId) {
		this.availabilityId = availabilityId;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "dateAvailable", nullable = false, length = 19)
	public Date getDateAvailable() {
		return this.dateAvailable;
	}

	public void setDateAvailable(Date dateAvailable) {
		this.dateAvailable = dateAvailable;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "dateexpires", nullable = false, length = 19)
	public Date getDateexpires() {
		return this.dateexpires;
	}

	public void setDateexpires(Date dateexpires) {
		this.dateexpires = dateexpires;
	}

	@Column(name = "visible", nullable = false)
	public boolean isVisible() {
		return this.visible;
	}

	public void setVisible(boolean visible) {
		this.visible = visible;
	}

	@Column(name = "deleted", nullable = false)
	public boolean isDeleted() {
		return this.deleted;
	}

	public void setDeleted(boolean deleted) {
		this.deleted = deleted;
	}

	@Column(name = "note", length = 500)
	public String getNote() {
		return this.note;
	}

	public void setNote(String note) {
		this.note = note;
	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "available")
	public Set<Property> getProperties() {
		return this.properties;
	}

	public void setProperties(Set<Property> properties) {
		this.properties = properties;
	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "available")
	public Set<Channel> getChannels() {
		return this.channels;
	}

	public void setChannels(Set<Channel> channels) {
		this.channels = channels;
	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "available")
	public Set<Media> getMedias() {
		return this.medias;
	}

	public void setMedias(Set<Media> medias) {
		this.medias = medias;
	}

}

I was seeing that some fields weren’t being created when I was using a FieldFactory, so I started tracing it backwards.

I create a new JPAContainer using JPAContainerFactory:

JPAContainer<Available>	availContainer = JPAContainerFactory.makeNonCached(Available.class, PublishConstants.PERSISTENCE_MEDIA);

however the properties that should represent the 2 booleans aren’t there. This snippet:


System.out.println("\navailContainer getContinerPropertyIds:");
Collection availContainerCol = availContainer.getContainerPropertyIds();
	for (Object o:availContainerCol)
	{
		System.out.println("-> "+(String)o);
	}

outputs this:

See how there are no properties for ‘visible’ or ‘deleted’. So for kicks I tried to create a BeanContainer out of the Available.class to see what fields it can find:

BeanContainer availBeanContainer = new BeanContainer(Available.class);

and this snippet:


System.out.println("\navailBeanContainer getContinerPropertyIds:");
Collection availBeanContainerCol = availBeanContainer.getContainerPropertyIds();
for (Object o:availBeanContainerCol)
{
System.out.println("-> "+(String)o);
}

outputs this:

So the ‘visible’ and ‘deleted’ properties found when using BeanContainer, but not with JPAContainer. Ceratinly I want to use JPAContainer so it can be persisted, and I need access to those fields, preferably without needing to add them manually after creating the container (but I will if I have to!). Note that the ‘note’ field is a simple column entry in the table, and it’s found - though it is a different datatype.

Does JPAContainerFactory find booleans?
What am I doing wrong that is causing JPAContainer to not find those properties?

thanks!

Hi Eric,

Good work, you found a bug! Could you please report it at
dev.vaadin.com
? You can then mark it for bugfix priority if you have a pro account subscription.

As a workaround until it gets fixed you can add (public!) getXyz() methods for the booleans which delegate to the isXyz() methods, or just rename is->get.

Thanks,
/Jonatan

Thanks Jonatan,

ticket created:

http://dev.vaadin.com/ticket/10402

I’ll give the is->get methods a whirl.

Cheers,
Eric

Out of curiosity, did I set up the ticket correctly?

http://dev.vaadin.com/ticket/10402

I know it’s not a priority item, but I just want to make sure it isn’t going to be lost somewhere and never reviewed…

Cheers,
Eric

Based on a quick glance, it looks good to me.
Now it is up to those working on the JPAContainer.

Are there any updates on this? I cannot change the naming of the getter and setter method of the Boolean attribute (“locked”) since it is generated by HyperJAXB…

Would it be a valid workaround to change the value using the entity of the item?

[code]
EntityItem person = persons.getItem(personTable.getValue());

// the following does not work (NullPointerException)
// person.getItemProperty(“locked”).setValue(“true”);

// valid to use entity instead?
person.getEntity().setLocked(Boolean.TRUE);

persons.commit();
[/code]Having performed some tests, this seems not to work… Does JPAContainer ignore the values written to the entity?

Florian