Bonjour à tous,

J'ai un problème concernant un refresh d'une entité pointant sur une SQL View.

Voici mon entité de base simplifiée:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 
@Entity
@Table(name = "prospection") 
public class Prospection extends AbstractRootEntity {
 
        @Id
	@Column(name = "Id")
	private Long id;
 
        @Column(name = "RaisonSociale", nullable = false, length = 100)
	private String raisonSociale;
 
        @OneToMany(mappedBy = "prospection", cascade = CascadeType.ALL)
	private List<RendezVous> rendezVous;
 
        @OneToMany(mappedBy = "prospection", cascade = CascadeType.ALL)
	private List<Appel> appels;
 
}
Et mon entité pointant sur une sql view permettant des agrégations de données:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
 
@Entity
@Table(name = "view_prospection")
public class ViewProspection implements Serializable {
 
	@Id
	@Column(name = "Id")
	private Long id;
 
	@Column(name = "RaisonSociale", nullable = false, length = 100)
	private String raisonSociale;
 
	@Column(name = "dateDernierAppel")
	@Temporal(TemporalType.TIMESTAMP)
	private Date dateDernierAppel;
 
	@Column(name = "dateProchainRappel")
	@Temporal(TemporalType.TIMESTAMP)
	private Date dateProchainRappel;
 
	@Column(name = "dateDernierRdv")
	@Temporal(TemporalType.TIMESTAMP)
	private Date dateDernierRdv;
 
	@Column(name = "dateProchainRdv")
	@Temporal(TemporalType.TIMESTAMP)
	private Date dateProchainRdv;
}
J'utilise une view car la requête générant les données de cette entité n'est pas compatible avec JPA 2.2 (problèmes de clause ON et de "de facto inner join")
Je voudrais à chaque update de l'entité Prospection, faire un refresh de la ViewProspection correspondante.

Voici mon service (Stateless Bean). Les DAO injectés sont des CDI bean contenant chacun un @PersistanceContext et permettent les opérations de base de façon non transactionnelle (merge, persist, find, refresh, flush):

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
 
@Stateless
public class ProspectionServiceImpl implements ProspectionService {
 
	@Inject
	private transient Logger logger;
 
	@Inject
	@Mapper(businessObject = BusinessObject.PROSPECTION)
	private IMapper mapper;
 
	@Inject
	@Mapper(businessObject = BusinessObject.VIEW_PROSPECTION)
	private IMapper viewMapper;
 
        @Inject
	private ProspectionDAOLocal daoProspection;
 
	@Inject
	private ViewProspectionDAOLocal daoViewProspection;	
 
        @Override
	public ProspectDTO editProspection(ProspectDTO prospection)
			throws Exception {
		ProspectDTO p = updateProspection(prospection);
		refreshView(p);
		return p;
	}
 
        private ProspectDTO updateProspection(ProspectDTO prospection) throws Exception {
		Prospection p = null;
		if(prospection.getId() == null)
			p = new Prospection();
		else 
			p = daoProspection.find(prospection.getId());
		if(p == null) {
			throw new ServiceException("Update prospection impossible car elle n'a pas été trouvée en base",null);
		}
		mapper.fillJPA(p, prospection);
		if(prospection.getId() == null)
			p = daoProspection.create(p);
		else 
			p = daoProspection.edit(p);
 
		daoProspection.flush();		
		mapper.fillDTO(p, prospection);			
		return prospection;		
	}
 
         private void refreshView(ProspectDTO prospection) throws DAOException {
		ViewProspection vp = daoViewProspection.find(prospection.getId());
		daoViewProspection.refresh(vp);
	}
}
Mon problème est que mon entité vue n'est pas rafraîchie après l'update car l'opération n'a pas été commit en base. Cette dernière est commit à la sortie de la méthode editProspection().
Je voudrais savoir quels @TransactionAttribute dois-je mettre sur mes méthodes afin de forcer le commit à la fin de la méthode updateProspection() et non editProspection().

Merci beaucoup!