Speeding up the creation of Log entity objects related to other objects

#1

In order to speed-up everything I would like to add log entities related to a device without touching (locking) the device entity. How can I do this with ObjectDB using @JoinColumn(name = "device") because I don't have a back reference from log to device!

-----

@Entity
public class Device {
    
    @Id @GeneratedValue
    private long id;
    
    @OneToMany(fetch = FetchType.EAGER, cascade={CascadeType.ALL}, orphanRemoval=true) @JoinColumn(name = "device")
    private List<Log> logs = new LinkedList<Log>();
    
}

@Entity
public class Log {
    
    @Id @GeneratedValue
    private long id;
    
    private LocalDateTime dateTime = null;
    
    @Enumerated(EnumType.STRING)
    private Level level = null;
    
    private String message = null;
    
}
#2

@JoinColumn is an ORM annotation that is silently ignored by ObjectDB.

You may want to use an inverse mapped-by relationship. Use a regular reference from Log to Device and mapped-by List<Log> field in Device. Inverse mapped-by fields are not stored in the database by loaded by running a query when needed. For that query to be efficient you may want to have an index on the reference field from Log to Device.

ObjectDB Support

Reply