156 words

How to avoid NULL values on Embedded entities

2017-02-24 02:24

Hi there. I'm new on this. trying to learn.

I'm trying to make a value non nulleable. So, when I try to upload to the DB this field as null, it give me an error.

I tried this, but it didn't work:

public class Pedido {
    @Id @GeneratedValue
    private long id;
    @Embedded private Direccion origen;
    @ManyToOne private Cliente cliente; //Opcional
    @Basic(optional=false) private Date fechaYhora; //Fecha en que se debe enviar el coche


public class Direccion {
    @Basic(optional=false) private String calle;
    @Basic(optional=false) private int numero;
    @Basic(optional=false) private String ciudad;
    @Basic(optional=false) private String provincia;
    @Basic(optional=false) private String pais;
    @Basic(optional=false) private int cp;



And how to make the emmbedeable Direccion not nulleable?

In the code above, the optional=false, works only on fechaYhora, but it doesn't work inside Direccion fields.

Sorry if my english is not perfecto, just ask if i'm not clear



Sorry. Solved. The code was working, the problem was that i'm savin an empty string "" (not null)

elnll002's picture
Joined on 2017-02-24
User Post #1

Post Reply

Please read carefully the posting instructions - before posting to the ObjectDB website.

  • You may have to disable pop up blocking in order to use the toolbar (e.g. in Chrome).
  • Use ctrl + right click to open the browser context menu in the editing area (e.g. for using a browser spell checker).
  • To insert formatted lines (e.g. Java code, stack trace) - select a style in the toolbar and then insert the text in the new created block.
  • Avoid overflow of published source code examples by breaking long lines.
  • You may mark in paragraph code words (e.g. class names) with the code style (can be applied by ctrl + D).
  • Long stack traces (> 50 lines) and complex source examples (> 100 lines) should be posted as attachments.
Maximum file size: 32 MB