0

i am trying to create a bidirectional one to many relationship.

@Entity
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = Company.FIND_ALL, query = "select c from Company 
})
public class Company {
public static final String FIND_ALL = "Company.findAll";

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private String email;
private String name;
private String phoneNumber;

@OneToMany(mappedBy = "company")
private List<Place> places;

private long millisSince1970;
private boolean deleted;

public Company() {

}

@PrePersist
public void addMillisPrePersist() {
    millisSince1970 = Instant.now().getEpochSecond();
    deleted = false;
}

@PreUpdate
public void addMillisPreUpdate() {
    millisSince1970 = Instant.now().getEpochSecond();
}

}

Place class:

@Entity
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = Place.FIND_ALL, query = "select p from Place p")
})
public class Place {
public static final String FIND_ALL = "Place.findAll";

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private Type type;
private String email;
private String name;
private String city;
private String address;
private String phoneNumber;
private String latitude;
private String longitude;
private String workingHours;
@ManyToOne
@JoinColumn(name = "company_id", referencedColumnName = "id", nullable = false)
private Company company;
@OneToMany(mappedBy = "place")
private List<SpecialOffer> specialOffers;
@OneToMany(mappedBy = "place")
private List<Event> events;

private long millisSince1970;
private boolean deleted;

public Place() {

}

@PrePersist
public void addMillisPrePersist() {
    millisSince1970 = Instant.now().getEpochSecond();
    deleted = false;
}

@PreUpdate
public void addMillisPreUpdate() {
    millisSince1970 = Instant.now().getEpochSecond();
}
}

And here is simple resource:

@GET
@Path("{companyId}")
@Produces({MediaType.APPLICATION_JSON})
public Company getCompany(@PathParam("companyId") int id) {
    return entityManager.find(Company.class, id);
}

In my database i have Company and Place tables, in the Place table i have a foreign key column named company_id, so when i try to get some Company which has some corresponding Place glassfish returns http status 500 internal server error without any exception, and server logs are empty, thus i can not debug or understand the cause of this problem. If i try to get the company which doesn't have any places it returns it without any problem. So what am i doing wrong?

P.S. i think my question is similar to this one Glassfish: HTTP 500 Internal Server Error without any exception which unfortunately doesn't have any responses

Community
  • 1
  • 1
Asiat
  • 401
  • 1
  • 5
  • 14
  • Look at the Server logfiles. There must be an exception – Jens Jan 20 '16 at 11:52
  • @jens looking at the domains/domain1/logs/server.log i can say that there are no exceptions, and i have only one domain. – Asiat Jan 20 '16 at 12:00
  • You have other logfiles? – Jens Jan 20 '16 at 12:01
  • @jens no, before this problem i already had http 500 but i could see the exception in log file or IDE console, however here log file is empty as well as the IDE console – Asiat Jan 21 '16 at 03:44
  • @Asiat I'm sitting with this issue, how did you debug glassfish without it printing anything to the Log? – Aj Otto Nov 28 '16 at 08:52
  • @AjOtto i couldn't find a solution to this problem, i just switched to another application server. – Asiat Dec 08 '16 at 04:16
  • @Asiat Hey, I don't remember exactly what caused the issue but i've solved it by fixing my annotations - there was a problem in my entities and I've switched from 'Resource-Local' to 'Jta' which caches much better and loads faster - also there's support for multiple entity managers, Did you deploy to a different server and it worked fine? an issue I can see is that you cannot have a Place without a Company, but you can have a Company without a Place - because of that Nullable = False – Aj Otto Dec 08 '16 at 08:14

0 Answers0