Question

I'm experiencing tynamo model module (org.tynamo:tapestry-model-web:0.3.1:jar) over Tapestry, and I'm facing an issue that I can't handle.

I've got two entities Client and Contract. Obviously, a client has many contracts :

Contract

@Entity
@BeanModels({ @BeanModel(reorder = "id") })
public class Contract {

    [...]

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name="contract_id")
    public Long getId() {
        return id;
    }

    /**
     * @return the client
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "client_id", nullable = true)
    public Client getClient() {
        return client;
    }

Client

@Entity
@BeanModels({ @BeanModel(reorder = "id") })
public class Client{

    [...]

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "client_id")
    public Long getId() {
        return id;
    }

    /**
     * @return the contracts
     */
    @OneToMany(cascade = { CascadeType.ALL })
    public List<Contract> getContracts() {
        return contracts;
    }

All is ok when I try to create a new client if I exclude Contract with

@BeanModels({ @BeanModel(exclude = "contrats") })

But if I try to add one without excluding contracts I get the following exception :

ERROR] pages.Add Render queue error in SetupRender[tynamo/PropertyEditBlocks:palette_set]: Failure reading parameter 'selected' of component tynamo/PropertyEditBlocks:palette_set: org.apache.tapestry5.ioc.internal.util.TapestryException
org.apache.tapestry5.ioc.internal.util.TapestryException: Failure reading parameter 'selected' of component tynamo/PropertyEditBlocks:palette_set: org.apache.tapestry5.ioc.internal.util.TapestryException [at classpath:org/tynamo/pages/PropertyEditBlocks.tml, line 39]
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl$AbstractPhase.invoke(ComponentPageElementImpl.java:153)
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl$SetupRenderPhase.render(ComponentPageElementImpl.java:181)
    at org.apache.tapestry5.internal.services.RenderQueueImpl.run(RenderQueueImpl.java:72)
    at org.apache.tapestry5.internal.services.PageRenderQueueImpl.render(PageRenderQueueImpl.java:124)
    at $PageRenderQueue_419b37801cb0d.render(Unknown Source)
    at $PageRenderQueue_419b37801cb0c.render(Unknown Source)

From my understanding of Palette component, that means the default selected values that should be present ... are not ! What is exact because there is no default value !

If I add a client directly in the database (MySQL) and don't exclude this field from my entity, I'm able to show and edit it without any problem, but still issue on adding a new one.

What did I missed ?

Was it helpful?

Solution

Just make sure your contract list has always a non-null value.

@Entity
@BeanModels({ @BeanModel(reorder = "id") })
public class Client{

    private List<Contract> contracts = new ArrayList<Contract>();

    @OneToMany(cascade = { CascadeType.ALL })
    public List<Contract> getContracts() {
        return contracts;
    }

[...]

}

BTW, careful with the bidirectional relationship between client and contract. In this case I think you are trying to map two sides of the same relationship but instead you are mapping two different relationships. Bidirectional relationships are always tricky, but that's for another question.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top