1

Al Salam Alaykom,

I'm trying to use hibernate annotation in one to many relation between Device and Positions Classes, one device has many positions. The problem that I'm getting a null list of positions when selecting the device, I tried a lot of solutions and nothing solve the problem

here's the relations part in my classes:

Device.java

@GwtTransient
private List<Position> positions = new LinkedList<Position>();

@OneToMany(mappedBy="device")
public List<Position> getPositions() {
    return positions;
}


public void setPositions(List<Position> positions) {
    this.positions = positions;
}

and Position.java

private Device device;

@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "device_id")
public Device getDevice() {
    return device;
}
public void setDevice(Device device) {
    this.device = device;
}

Also, I tried the following annotations:

//In Device:
@OneToMany(mappedBy = "device")
@LazyCollection(LazyCollectionOption.FALSE)

//In Position:
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumns({@JoinColumn(name = "device_id", insertable=false, updatable=false)})

/***********************************************************************************/

//In Device:
@OneToMany(mappedBy = "device",fetch = FetchType.EAGER)
@LazyCollection(LazyCollectionOption.FALSE)
@Fetch(FetchMode.SELECT)    

//In Position:
@ManyToOne
@JoinColumn (name="device_id")

/***********************************************************************************/

//In Device:
@OneToMany(mappedBy = "device")
@LazyCollection(LazyCollectionOption.FALSE)

//In Position:
@ManyToOne
@PrimaryKeyJoinColumn

/***********************************************************************************/ //In Device:

@OneToMany(mappedBy = "device", cascade = javax.persistence.CascadeType.ALL, fetch=FetchType.EAGER)
@Fetch(FetchMode.SELECT)
@LazyCollection(LazyCollectionOption.FALSE)

//In Position:
@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "device_id")

Any help will be appreciated... Thank you

Mohammad Sayed
  • 146
  • 1
  • 8
  • where you have nulls values ? In your frontend or you have check the values just after select ? It may be caused by @GwtTransient – Josef Prochazka Dec 01 '14 at 09:45
  • Two questions please: (1) could you post an example of your 'insert' code, in particular are you making sure that the java references point both ways (2) after your insert, did you try and peek in your database - could you tell what data you see there. – Pelit Mamani Dec 01 '14 at 10:50
  • @PelitMamani I'm using Traccar system for tracking device it's open source and the input method implied in the server and data inserted correctly and they are exist in the database. The problem is in reading from database. and please read the following comment – Mohammad Sayed Dec 02 '14 at 12:13
  • @JosefProcházka the problem was in backend for first time and the list came with null value, but while I was trying to read after selection there something strange happened... I loop over all devices and when I type: device.setPositions(device.getPositions()) the list full of data !!!!!! Now in the front end the value is null again :'( and Yes now it's because of '@GwtTransient' and I don't know how to transfer a list without '@GwtTransient' because it makes a compilation error for serialization – Mohammad Sayed Dec 02 '14 at 12:15

0 Answers0