Bonjour Salem ,
voici les 2 fichier de mapping en sachant que j ai déja crée un synonym pour ma table2 qui se trouve dans le schema 2
MyApp.hbm.xml<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping> <class lazy="false" name="com.inet.kor.training.myapp.models.MyAppImpl" table="KO1QTAP" >
<id name="code" type="string"> <column name="CODE" length="50" not-null="true" />
</id> <one-to-one name="appBean" class="com.inetpsa.sts.security.bean.Application"
constrained="true" />
</class></hibernate-mapping>Application.hbm.xml
<?xml version="1.0"?><!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="com.inet.sts.security.bean"> <class name="Application" table="STSQTAP" lazy="false">
<id name="code" type="string"> <column name="CODE" length="50" not-null="true" />
</id> <property name="url" type="string">
<column name="URL" length="255" /> </property>
</class></hibernate-mapping>les 2 Managers que j ai crée
MyAppImpl Managerpublic class MyAppImpl implements MyApp {
/**
* the reference to
Application Bean
*/
private Application appBean; /**
* the serialVersionUID
*/
private static final long serialVersionUID = 1L;
/**
* the code
*/
private String code;
/**
* getter code
*
* @return Returns the code
*/
public String getCode() {
return this.code;
}
/**
* setter code
*
* @param code
* the code to set
*/
public void setCode( String code) {
this.code = code;
}
/**
* getter AppBean
* @return Returns the appBean
*/
public Application getAppBean() {
return this.appBean;
}
/**
* Setter Appbean
* @param appBean the appBean to set
*/
public void setAppBean(Application appBean) {
this.appBean = appBean;
}
}
Application Manger
/**
* this class stores data about remote/external web apps. It is referenced in
* <code>Transaction</code>
*
* @author u189723
*
*/
public class Application implements Serializable {
/**
* serialVersionUID
*/
private static final long serialVersionUID = 4496446219238946191L;
/**
* the user friendly identification of an app.
*/
private String code;
/**
* the base url. of remote app.
*/
private String url;
/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (!(other instanceof Application)) {
return false;
}
final Application app = (Application) other;
if (!app.getCode().equals(getCode())) {
return false;
}
return true;
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
final int hashInitial = 29;
final int hashMult = 17;
// pick a hard-coded, randomly chosen, non-zero, odd number pair
// ideally different for each class
return (new HashCodeBuilder(hashInitial, hashMult)).append(this.code)
.toHashCode();
}
/**
* Get the code.
*
* @return Returns the code
*/
public String getCode() {
return this.code;
}
/**
* Set the code.
*
* @param code
* the code to set
*/
public void setCode(String code) {
this.code = code;
}
/**
* Get the url.
*
* @return Returns the url
*/
public String getUrl() {
return this.url;
}
/**
* Set the url.
*
* @param url
* the url to set
*/
public void setUrl(String url) {
this.url = url;
}
}
pour ma class de test public class MyAppManagerImplTest extends AbstractTestCase {
/**
* the app
*/
private Application app;
/**
* the myapplicationimpl
*/
@Resource(name="myAppManager")
private MyAppManager myapplication; /**
* getter MyapplicationImpl
* @return Returns the myapplicationimpl
*/
public MyAppManager getMyapplication() {
return this.myapplication;
}
/**
* setter MyapplicationImpl
* @param myapplication the myapplication to set
*/
public void setMyapplication(MyAppManager myapplication) {
this.myapplication = myapplication;
}
/**
* Test the Managed Class
*
*/
@Test
public void testGetManagedClass() {
Assert.assertEquals(MyAppImpl.class, new MyAppMangerImpl()
.getManagedClass());
}
/**
* Test the ManagedKeyClass
*
*/
@Test
public void testGetManagedKeyClass() {
Assert.assertEquals(String.class, new MyAppMangerImpl().getManagedKeyClass());
}
/**
* Test the ManagedColumnClass
*
*/
@Test
public void testGetManagedColumnClass() {
Assert.assertEquals(MyAppMangerImpl.Columns.class, new MyAppMangerImpl()
.getManagedColumnClass());
}
/**
* Test the ManagedColumns
*
*/
@Test
public void testGetManagedColumns() {
Assert.assertArrayEquals(MyAppMangerImpl.Columns.values(),
new MyAppMangerImpl().getManagedColumns());
}
c ést la methode que je voulais testé
/**
* Tests the getBeanById to check the Hibernate Mapping
*/
@Test public void getBean() {
try { final String code = "ARCTEC";
MyApp myapp = myapplication.getBeanById(code);// assertNotNull(myapp);
// assertNotNull(myapp.getAppBean()); assertEquals(myapp.getAppBean().getCode(), myapp.getCode());
} catch (StsNotFoundException e) { e.printStackTrace();
} catch (StsUndeterminedTechnicalException e) { e.printStackTrace();
} catch (StsBusinessException e) { e.printStackTrace();
} } }
c est pas tres important de mettre les Bean et les DAO que j ai crée
msg d erreur générer Failed while accessing to class com.inet.kor.training.myapp.models.MyAppImpl with id=[ARCTEC]
org.springframework.dao.InvalidDataAccessResourceUsageException:could not load an entity: [com.inet.kor.training.myapp.models.MyAppImpl#ARCTEC]; nested exception is org.hibernate.exception.SQLGrammarException: could not load an entity: [com.inet.kor.training.myapp.models.MyAppImpl#ARCTEC]
org.hibernate.exception.SQLGrammarException: could not load an entity: [com.inet.kor.training.myapp.models.MyAppImpl#ARCTEC]
<- Best regards ->
-=NY=-