1

Here is my modele

@Entity
public class Structure implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue
private Integer idt_structure;
private String name;
@ManyToOne
@JoinColumn(name="idt_parent_structure")
private Structure structure;
// Getters and setters
}

Example of input and outpu

Input

 public void save(){
 Structure structure = new Structure();
 structure.setName("structure");
 structure.setStructure(null);
 structureService.add(structure);
 }

Here is my Service

Transactional
@Service("structureService")
public class StructureServiceImpl implements IStructureService{
@Autowired
@Qualifier("structureDao")
private StructureDao structureDao;
private List<Structure> structures;
public StructureServiceImpl() {
 super();
}
@Override
public void addStructure(Structure structure) {
 structureDao.save(structure);
}
// getters and setters
}

Here is My DAO

@Repository
public class StructureDao extends GenericDaoHibernateImpl<Structure, Integer> {
@Autowired
@Qualifier("sessionFactory")
private SessionFactory sessionFactory;
@Autowired
public StructureDao(@Qualifier("sessionFactory") SessionFactory sessionFactory) {
 super(sessionFactory);
}
}

SQL SCHEMA TABLE Structure idt_structure int(11), name varchar(255), idt_parent_structure int(11). And all columns All columns can take the value null unless idt_structure

Output in datadase

sql schema : idt_structure, name , idt_parent_structure.

structure(1,name,0);

and i want to have output like this

structure(1,name,null);

The default value of an Integer is 0 And I want to have null in sql database for the idt_parent_structure column.

asked Jun 2, 2017 at 10:01
5
  • 1
    Please show a minimal reproducible example. What is your database schema? How do you store the data in the DB? How do you generate the output? etc. Commented Jun 2, 2017 at 10:08
  • Why do you want to see null in id field? In most cases it would be wrong Commented Jun 2, 2017 at 10:12
  • @assylias thank u for ur reply i update my post to see more details. Commented Jun 2, 2017 at 10:17
  • please add structureDao.save, configuration of your ORM and DB schema. DB schema and configuration is important since it depends on not only code Commented Jun 2, 2017 at 10:37
  • @ADS i'm using GenericDaoHibernateImpl it's generic but u can see i update my post Commented Jun 2, 2017 at 10:49

1 Answer 1

0

Since you write @GeneratedValue you don't manage what exactly id would be.


Provide us complete example and we'll help you

answered Jun 2, 2017 at 10:11
Sign up to request clarification or add additional context in comments.

3 Comments

thank for ur reply but not the id i want to have null in the idt_parent_structure
@Rodik I can't understand you. Could you rephrase your question?
Ok, I have a structure object that contains a parent object of the same type tt the time of inserting the structure object, I enter the name of this structure and If I select parent object the idt_parent_structure column in sql takes the id of the selected objet. In the second case If I don't select parent object when inserting The value of idt_parent_structure takes 0. And i want to have null not 0.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.