2

I am currently writing a Netbeans platform application for persistence I use JPA 2.1 and eclipse link as provider. I have the following entity class:

import java.util.UUID;
import javafx.beans.property.SimpleStringProperty;
import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Transient;

/**
 *
 * @author forell
 */
@Entity
@Access(AccessType.FIELD)
public class MaterialAbc {
    @Id
    private String id;

//... several additional fields, that all work fine


    private String substanceInstances = "";


    public MaterialAbc(){
        id = UUID.randomUUID().toString();
    }

    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }


//.. getters and setters for the omitted fields        
    public String getSubstanceInstances() {
        return substanceInstances;
    }

    public void setSubstanceInstances(String substanceInstances) {
        this.substanceInstances = substanceInstances;
    }

    /*  IF I UNCOMMENT THESE LINES THE DATATABLE IS NOT CREATED ANYMORE
        IS THERE A WAY TO SOLVE THIS?

    public List<SubstanceInstance2> getSubs() {
        List<SubstanceInstance2> subs = new ArrayList<>();

        if (!"".equals(substanceInstances)){

            List<String> values = Arrays.asList(substanceInstances.split("|"));
            values.forEach(value->{
                subs.add(SubstanceInstance2.unSerialize(value));
            });

        }
        return subs;
    }
    public void setSubs(List<SubstanceInstance2> subs) {
        substanceInstances = "";
        subs.forEach(sub->{
            substanceInstances =substanceInstances + sub.serialize() + "|";
        });
        substanceInstances = substanceInstances.substring(0, substanceInstances.length()-1);
    }
*/

As is the class works fine, as soon as I uncomment the two methods at the bottom that "unserialize" an object that is nested in the string substanceInstances, eclipselink is not creating the datatables anymore. Is there a way to solve this, or do need to add an extra layer.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Alexander
  • 21
  • 4

1 Answers1

0

In the meantime I actually found a solution to the problem. It seems eclipselink does not convert the Entity-bean into a table, if there are lambda expressions used in the methods. In the end I converted

values.forEach(value->{
    subs.add(SubstanceInstance2.unSerialize(value));
});

into

for (String value:values){
    subs.add(SubstanceInstance2.unSerialize(value));
}

And everthing works nicely. As to the reason why, no idea!

Alexander
  • 21
  • 4