a propos de mapping hibernate

51 views
Skip to first unread message

yosri naghmouchi

unread,
Nov 12, 2010, 3:16:11 AM11/12/10
to TeeJUG
Bonjour tout le monde,
le problme c est que je voulais faire un mapping hibernate de 2 table
dans une même base de donnée (oracle 10g) mais qui sont dans deux
schéma différent . Au niveaux des fichiers hmb.xml de l une de ces
table j ai fais une association one-to-one et au niveau des classes
java j ai fais une référence vers l une des class bien sur avec les
getter/setter qui correspond a chaque table et en fin j ai réalise une
classe de test avec jnit4 pour tester l application et la console m
affiche que
"Failed while accessing to class com.*.MyAppImpl with id= []"
ma question est pour quoi hibernate n arrive pas a faire le mapping
de 2 table dans deux shéma différente
?

fares mellouli

unread,
Nov 12, 2010, 4:17:39 AM11/12/10
to tee...@googlegroups.com
Salut Yosri,

As-tu pensé à créer un synonyme publique oracle de la table 2 dans le schema 1 ?

PS: pour créer un synonyme en oracle tu peux utiliser la requete suivante :
create public synonym TABLE_NAME2 for SCHEMA2.TABLE_NAME2;

Bon courage.
Fares MALLOULI


--
Vous recevez ce message, car vous êtes abonné au groupe Google Groupes TeeJUG.
Pour envoyer un message à ce groupe, adressez un e-mail à tee...@googlegroups.com.
Pour vous désabonner de ce groupe, envoyez un e-mail à l'adresse teejug+un...@googlegroups.com.
Pour plus d'options, consultez la page de ce groupe : http://groups.google.com/group/teejug?hl=fr




yosri naghmouchi

unread,
Nov 12, 2010, 5:16:25 AM11/12/10
to tee...@googlegroups.com
Bonjour Fares ,
Merci pour ta réponse .J  ai essayé de le faire mais apparemment j ai pas le droit d exécuter la commande create synonym"privilège insuffisants"  en plus la base est sur un serveur distant  dans l autre bout du monde et donc ça demande trop de temps d attente pour avoir une réponse . il y a pas d autre manière pour réalisé le mapping cad faire des modif au niveau de la conf d hibernate ou de spring?

<-  Best regards ->
       -=NY=-

benafia salem

unread,
Nov 12, 2010, 4:08:48 AM11/12/10
to tee...@googlegroups.com
Salam,

ça sera un peu difficile de résoudre ton pb sans que vous postiez les codes sources et la configuration.
à première vue, t'as looper quelque chose dans le mapping.

Bonne journée.

Le 12 novembre 2010 09:16, yosri naghmouchi <nyosr...@gmail.com> a écrit :
--
Vous recevez ce message, car vous êtes abonné au groupe Google Groupes TeeJUG.
Pour envoyer un message à ce groupe, adressez un e-mail à tee...@googlegroups.com.
Pour vous désabonner de ce groupe, envoyez un e-mail à l'adresse teejug+un...@googlegroups.com.
Pour plus d'options, consultez la page de ce groupe : http://groups.google.com/group/teejug?hl=fr




--
Salem Ben Afia,
Knowledgeware
salem.b...@gmail.com
(216) 96 18 96 47
(216) 23 20 00 09

yosri naghmouchi

unread,
Nov 12, 2010, 8:26:16 AM11/12/10
to tee...@googlegroups.com
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 Manager


public 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=-


kamel mahdi

unread,
Nov 12, 2010, 1:59:55 PM11/12/10
to tee...@googlegroups.com
Salut,

Essaie de vérifier les droits de ton utilisateur (utilisé pour la connexion hibernate) sur le synonyme que t'as créer(schéma 2).


--Kamel MAHDI.

Nizar GARRACHE

unread,
Jan 3, 2011, 11:13:52 AM1/3/11
to tee...@googlegroups.com
Salut Yosri,

Essais de mettre l'attribut schema au niveau de la balise hibernate-mapping et/ou class...

Bon courage ;)

--- En date de : Ven 12.11.10, yosri naghmouchi <nyosr...@gmail.com> a écrit :
Reply all
Reply to author
Forward
0 new messages