Skip to main content
Bumped by Community user
Bumped by Community user
added 1640 characters in body
Source Link
Atekur Rahman
  • 301
  • 1
  • 4
  • 11

I have @OneToMany relationship between FabricRoll and FabricDefect.

@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY) @JoinColumn(name = "fabric_roll_id", referencedColumnName = "fabric_roll_id") private Set<FabricDefect> fabricDefects = new HashSet<>(); 

The problem is when I get FabricRoll by JpaRepository function

findAll()

the associate FabricDefect is also loaded.

I want to load only FabricRoll and FabricDefect should load when calling the function getFabricDefect()

FabricRollServiceImpl class

@Component public class FabricRollServiceImpl implements IFabricRollService{ @Autowired FabricRollRepository fabricRollRepository; @Transactional(propagation = Propagation.REQUIRED) @Override public List<FabricRoll> getAllFabricRoll() { FabricRoll fabricRoll1 = new FabricRoll(); fabricRoll1.setBatchNo("34344"); fabricRoll1.setLotNo("425"); fabricRoll1.setPoNo("42"); fabricRoll1.setRollLength(2343); fabricRoll1.setRollNo("356"); fabricRoll1.setRollWidth(60); fabricRoll1.setStyleNo("354"); FabricDefect fabricDefect = new FabricDefect(); fabricDefect.setDefectNote("note"); fabricDefect.setDefectPoint(3); fabricDefect.setSegment(3); fabricDefect.setYard(42); Set<FabricDefect> fabricDefects = new HashSet<>(); fabricDefects.add(fabricDefect); fabricRoll1.setFabricDefects(fabricDefects); addFabricRoll(fabricRoll1); FabricRoll fabricRoll = null; return fabricRollRepository.findAll(); } @Override public void addFabricRoll(FabricRoll fabricRoll) { fabricRollRepository.save(fabricRoll); } 

}

Break point: enter image description here

Console: enter image description here

I have @OneToMany relationship between FabricRoll and FabricDefect.

@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY) @JoinColumn(name = "fabric_roll_id", referencedColumnName = "fabric_roll_id") private Set<FabricDefect> fabricDefects = new HashSet<>(); 

The problem is when I get FabricRoll by JpaRepository function

findAll()

the associate FabricDefect is also loaded.

I want to load only FabricRoll and FabricDefect should load when calling the function getFabricDefect()

I have @OneToMany relationship between FabricRoll and FabricDefect.

@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY) @JoinColumn(name = "fabric_roll_id", referencedColumnName = "fabric_roll_id") private Set<FabricDefect> fabricDefects = new HashSet<>(); 

The problem is when I get FabricRoll by JpaRepository function

findAll()

the associate FabricDefect is also loaded.

I want to load only FabricRoll and FabricDefect should load when calling the function getFabricDefect()

FabricRollServiceImpl class

@Component public class FabricRollServiceImpl implements IFabricRollService{ @Autowired FabricRollRepository fabricRollRepository; @Transactional(propagation = Propagation.REQUIRED) @Override public List<FabricRoll> getAllFabricRoll() { FabricRoll fabricRoll1 = new FabricRoll(); fabricRoll1.setBatchNo("34344"); fabricRoll1.setLotNo("425"); fabricRoll1.setPoNo("42"); fabricRoll1.setRollLength(2343); fabricRoll1.setRollNo("356"); fabricRoll1.setRollWidth(60); fabricRoll1.setStyleNo("354"); FabricDefect fabricDefect = new FabricDefect(); fabricDefect.setDefectNote("note"); fabricDefect.setDefectPoint(3); fabricDefect.setSegment(3); fabricDefect.setYard(42); Set<FabricDefect> fabricDefects = new HashSet<>(); fabricDefects.add(fabricDefect); fabricRoll1.setFabricDefects(fabricDefects); addFabricRoll(fabricRoll1); FabricRoll fabricRoll = null; return fabricRollRepository.findAll(); } @Override public void addFabricRoll(FabricRoll fabricRoll) { fabricRollRepository.save(fabricRoll); } 

}

Break point: enter image description here

Console: enter image description here

Formatted/Indented the question.
Source Link

I have @OneToMany@OneToMany relationship between FabricRollFabricRoll and FabricDefectFabricDefect.

@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY) @JoinColumn(name = "fabric_roll_id", referencedColumnName = "fabric_roll_id") private Set<FabricDefect> fabricDefects = new HashSet<>(); 

The problem is when I get FabricRollFabricRoll by JpaRepositoryJpaRepository function

findAll()

the associate FabricDefectFabricDefect is also loaded.

I want to load only FabricRollFabricRoll and FabricDefect willFabricDefect should load when calling the function getFabricDefect()

I have @OneToMany relationship between FabricRoll and FabricDefect.

@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY) @JoinColumn(name = "fabric_roll_id", referencedColumnName = "fabric_roll_id") private Set<FabricDefect> fabricDefects = new HashSet<>(); 

The problem is when get FabricRoll by JpaRepository function

findAll()

associate FabricDefect also loaded.

I want to load only FabricRoll and FabricDefect will load when calling the function getFabricDefect()

I have @OneToMany relationship between FabricRoll and FabricDefect.

@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY) @JoinColumn(name = "fabric_roll_id", referencedColumnName = "fabric_roll_id") private Set<FabricDefect> fabricDefects = new HashSet<>(); 

The problem is when I get FabricRoll by JpaRepository function

findAll()

the associate FabricDefect is also loaded.

I want to load only FabricRoll and FabricDefect should load when calling the function getFabricDefect()

Source Link
Atekur Rahman
  • 301
  • 1
  • 4
  • 11
Loading