[JPA]problèmes de read-only et de merge
Bonjour,
j'ai des problèmes pour paramétrer correctement mon application appuyée sur Spring et JPA.
1°) Certaines tables ne m'appartiennent pas et je souhaiterai pouvoir positionner un paramètre read-only quelque part, mais je n'ai pas trouvé où, dans quelle annotation.
Au contraire au lancement du serveur je m'aperçois que sans que je lui ai demandé, il y a des tentatives du programme de créer des index ou clés étrangères sur les tables en question si par exemple j'utilise deux tables pour alimenter une entité.
Le seul moyen que j'ai trouvé pour protéger ces tables est de ne faire aucune jointure sql ou hdl, et de gérer le remplissage à la main dans le programme ! pas cool !
2°) mon deuxième problème:
sur une table qui m'appartient et que je souhaite mettre à jour, la lecture fonctionne bien, mais le merge ne fonctionne pas ! A la place un select est exécuté, et aucun update !
Qu'est-ce qui pourrait bien empêcher cet update sur une table pour laquelle j'ai tous les droits ?
voici mon dao.xml (extraits)
Code:
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 55 56
|
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
<bean id="dataSourceApo" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="maxActive" value="100" />
<property name="maxIdle" value="30" />
<property name="maxWait" value="100" />
<property name="url"
value="jdbc:oracle:thin:@*****:1521:******" />
<property name="username" value="****" />
<property name="password" value="*****" />
</bean>
<bean id="entityManagerFactoryApo"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSourceApo" />
<property name="jpaVendorAdapter" ref="jpaVendorAdapter" />
<property name="persistenceUnitName" value="managerApo" />
<property name="persistenceXmlLocation" value="classpath:/properties/dao/persistence.xml" />
<property name="jpaProperties" ref="jpaProperties" />
</bean>
<bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactoryApo" />
</bean>
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="*" propagation="SUPPORTS" read-only="true" />
</tx:attributes>
</tx:advice>
<tx:annotation-driven transaction-manager="txManager" />
<bean id="jpaVendorAdapter"
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="true" />
<property name="generateDdl" value="true" />
<property name="database" value="ORACLE" />
</bean>
<util:properties id="jpaProperties">
<prop key="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</prop>
<prop key="hibernate.cache.use_query_cache">false</prop>
<prop key="hibernate.cache.use_second_level_cache">false</prop>
</util:properties>
<bean id="apoDaoService" class="org.esupportail.apobilitation.dao.ApoJPADaoServiceImpl" lazy-init="true">
<description>
This bean is the DAO service, the interface used by the
domain service to access
the database. It must implement interface
org.esupportail.esup_apobilitation.dao.DaoService.
</description>
</bean> |
et dans mon persitence.xml
Code:
1 2 3 4 5
|
<persistence-unit name="managerApo" transaction-type="RESOURCE_LOCAL" >
<class>org.esupportail.apobilitation.domain.beans.apogee.TypeUtilisateur</class>
<class>org.esupportail.apobilitation.domain.beans.hab.HabTypUti</class>
</persistence-unit> |
mon entité (j'ai commenté le code avec deux tables qui provoque une tentative indésirée de création d'index)
Code:
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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
|
package org.esupportail.apobilitation.domain.beans.hab;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.SecondaryTable;
import org.esupportail.apobilitation.domain.beans.apogee.TypeUtilisateur;
/**
* @author mcollas
*
*/
@Entity
@Table(name="HAB_TYP_UTI" )
//@SecondaryTable(name="TYP_UTILISATEUR",
//pkJoinColumns={
//@PrimaryKeyJoinColumn(name="COD_TUT")})
public class HabTypUti implements Serializable {
/**
* serial
*/
private static final long serialVersionUID = 2257608896657447617L;
/**
* type utilisateur
*/
@Id
@Column(name="COD_TUT")
private String codTut;
/**
* temoin autorisation utiliser ce type "O"= oui "N"=interdit
*/
@Column(name="TEM_AUT_TUT")
private String temAutTut;
/**
* resume des droits pour affichage
*/
@Column(name="TUT_RESUME")
private String tutResume;
/**
* type utilisateur Apogee
*/
@Transient
private TypeUtilisateur typUti;
/**
* temoin autorisation utiliser ce type true= oui false=interdit
*/
@Transient
private boolean autorise;
/**
*
*/
// @Column(name = "LIB_CMT_TUT", table="TYP_UTILISATEUR", updatable=false)
@Transient
private String libCmtTut;
/**
*
*/
// @Column(name = "LIB_TUT", table="TYP_UTILISATEUR", updatable=false)
@Transient
private String libTut;
/**
*
*/
// @Column(name = "TEM_COF_NOT", table="TYP_UTILISATEUR", updatable=false)
@Transient
private String temCofNot;
/**
* @return the codTut
*/
public String getCodTut() {
return codTut;
}
/**
* @param codTut the codTut to set
*/
public void setCodTut(String codTut) {
this.codTut = codTut;
}
/**
* @return the typUti
*/
public TypeUtilisateur getTypUti() {
return typUti;
}
/**
* @param typUti the typUti to set
*/
public void setTypUti(TypeUtilisateur typUti) {
this.typUti = typUti;
}
/**
* @return the temAutTut
*/
public String getTemAutTut() {
return temAutTut;
}
/**
* @param temAutTut the temAutTut to set
*/
public void setTemAutTut(String temAutTut) {
this.autorise= (temAutTut=="O") ? true:false;
this.temAutTut = temAutTut;
}
/**
* @return the tutResume
*/
public String getTutResume() {
return tutResume;
}
/**
* @param tutResume the tutResume to set
*/
public void setTutResume(String tutResume) {
this.tutResume = tutResume;
}
/**
* @return the autorise
*/
public boolean isAutorise() {
return autorise;
}
/**
* @param autorise the autorise to set
*/
public void setAutorise(boolean autorise) {
this.temAutTut= autorise ? "O":"N";
this.autorise = autorise;
}
/**
* @return the libCmtTut
*/
public String getLibCmtTut() {
return libCmtTut;
}
/**
* @param libCmtTut the libCmtTut to set
*/
public void setLibCmtTut(String libCmtTut) {
this.libCmtTut = libCmtTut;
}
/**
* @return the libTut
*/
public String getLibTut() {
return libTut;
}
/**
* @param libTut the libTut to set
*/
public void setLibTut(String libTut) {
this.libTut = libTut;
}
/**
* @return the temCofNot
*/
public String getTemCofNot() {
return temCofNot;
}
/**
* @param temCofNot the temCofNot to set
*/
public void setTemCofNot(String temCofNot) {
this.temCofNot = temCofNot;
}
} |
et le code avec le merge dans ApoJPADaoServiceImpl.java
Code:
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
|
public List<HabTypUti> getHabTypUtis() {
logger.info("dans getHabTypUtis dao ");
Query q = entityManager
.createQuery("SELECT htu FROM HabTypUti htu");
@SuppressWarnings("unchecked")
List<HabTypUti> ret = q.getResultList();
Map<String, TypeUtilisateur> mapTut = this.getMapTypeUtilisateurs();
for (HabTypUti htu : ret) {
htu.setTypUti(mapTut.get(htu.getCodTut()));
htu.setLibCmtTut(htu.getTypUti().getLibCmtTut());
htu.setLibTut(htu.getTypUti().getLibTut());
}
return ret;
}
/**
* @see org.esupportail.apobilitation.dao.ApoDaoService#updateHabTypUti(org.esupportail.apobilitation.domain.beans.hab.HabTypUti)
*/
@Override
public void updateHabTypUti(HabTypUti habTypUti) {
logger.info("dans updateHabTypUti dao");
HabTypUti htu= entityManager.merge(habTypUti);
logger.info("dans update après merge");
} |
Là je sèche pour trouver ce qui empêche le merge d'exécuter un update: voici les traces:
Code:
1 2 3 4
| 2011-03-21 10:04:25,019 INFO [org.esupportail.apobilitation.web.controllers.TypesUtilisateursController] - dans updateType
2011-03-21 10:04:25,019 INFO [org.esupportail.apobilitation.dao.ApoJPADaoServiceImpl] - dans updateHabTypUti dao
Hibernate: select habtyputi0_.COD_TUT as COD1_1_0_, habtyputi0_.TEM_AUT_TUT as TEM2_1_0_, habtyputi0_.TUT_RESUME as TUT3_1_0_ from HAB_TYP_UTI habtyputi0_ where habtyputi0_.COD_TUT=?
2011-03-21 10:04:25,026 INFO [org.esupportail.apobilitation.dao.ApoJPADaoServiceImpl] - dans update après merge |