-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 23 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Strange brehaviour (could not execute batch update exceptio)
PostPosted: Wed Apr 04, 2007 8:00 am 
Newbie

Joined: Mon Mar 19, 2007 6:15 pm
Posts: 19
Location: Bilbao (Spain)
Ok, here it goes my question. I have a User POJO and a Media POJO, both mapped with a bidirectional (one-to-many / many-to-one) relationship. And when I try to retrieve the "UploadedMedia" from a returned user I get a strange Exception.

Hibernate version: 3.2

Mapping documents:
Code:
@User.hbm.xml

<hibernate-mapping auto-import="true" default-lazy="false">   
    <class name="com.mimetics.beans.User" table="users">       
        <id name="email" type="java.lang.String" column="email">
            <generator class="native"/>
        </id>
        <property name="name" type="java.lang.String" column="name" not-null="true" length="45"/>
        <property name="surname" type="java.lang.String" column="surname" not-null="true" length="45"/>
        <property name="country" type="java.lang.String" column="country" not-null="true" length="255"/>
        <property name="nickname" type="java.lang.String" column="nickname" not-null="true" length="45"/>
        <property name="password" type="java.lang.String" column="password" not-null="true" length="12"/>
        <many-to-one name="userPreferences"  class="com.mimetics.beans.UserPreferences"
                     foreign-key="fk_user_user_preferences" column="preferences"  not-null="true"/>
        <many-to-one name="userType"  class="com.mimetics.beans.UserType"
                     foreign-key="fk_user_user_types" column="type"  not-null="true"/>
       
        <!-- Collection Sets -->
        <set name="uploadedMedia" inverse="true" lazy="true">
            <key not-null="true" column="owner"/>
            <one-to-many class="com.mimetics.beans.Media"/>
        </set>
       
        <!-- SENT & RECEIVED MESSAGES -->
        <set name="sentMessages" table="messages" lazy="true" >
            <key not-null="true" column="from"/>
            <one-to-many class="com.mimetics.beans.Message"/>
        </set>
        <set name="receivedMessages" table="messages" lazy="true">
            <key not-null="true" column="to"/>
            <one-to-many class="com.mimetics.beans.Message"/>
        </set>
        <!-- POSTED COMMENTS -->
        <set name="postedComments" lazy="true">
            <key not-null="true" column="email"/>
            <one-to-many class="com.mimetics.beans.Comment" />
        </set>
    </class>
</hibernate-mapping>


Code:
@Media.hbm.xml
<hibernate-mapping auto-import="true" default-lazy="false">
   
    <!-- Indicamos la clase a persistir y la tabla a la que corresponde-->
    <class name="com.mimetics.beans.Media" table="media">
       
        <!-- Especificamos la clave primaria -->
        <id name="mediaId" type="java.lang.Long" column="media_id">
            <generator class="native"/>
        </id>
       
        <!-- A continuación el resto de atributos -->
        <property name="fileName" type="java.lang.Long" column="filename" not-null="true"/>
        <property name="size" type="java.lang.Long" column="file_size" not-null="true"/>
        <property name="sizeMb" type="java.lang.Integer" column="file_size_mb" not-null="true"/>
        <property name="path" type="java.lang.String" column="path" not-null="true" />
        <property name="description" type="java.lang.String" column="description" not-null="false"/>
        <property name="views" type="java.lang.Long" column="views" not-null="true" />
        <property name="title" type="java.lang.String" column="title" not-null="false" />
        <property name="tags" type="java.lang.String" column="tags" not-null="false" />
        <property name="uploadDate" type="java.util.Date" column="upload_date" not-null="true"/>
       
        <many-to-one name="mediaType" class="com.mimetics.beans.MediaType"
                     foreign-key="fk_media_media_types" column="type" not-null="true" />
       
        <many-to-one name="owner" class="com.mimetics.beans.User"
                     foreign-key="fk_media_users" column="owner" not-null="true" insert="false" update="false"/>
                     
        <set name="receivedComments" lazy="true">
            <key not-null="true" column="media_id"/>
            <one-to-many class="com.mimetics.beans.Comment" />
        </set>
       
    </class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
I use a "Manager" approach for getting the SessionFactory and a Session object, here are the clases:

Code:
public class Manager implements IManager
{
    private Session session = null;
    /**
     * Creates a new instance of Manager
     */
    public Manager (Session session)
    {
        this.session = session;
    }
   
    public Session getSession ()
    {
        return this.session;
    }
    public  void begin ()
    {
       
        if (this.getSession () != null)
           this.getSession ().beginTransaction ();
    }
   
    public void commit ()
    {
        if (this.getSession () != null)
            this.getSession ().getTransaction ().commit ();
    }
   
    public void rollback ()
    {
       
        if (this.getSession () != null)
        {
            try
            {
                this.getSession ().getTransaction ().rollback ();
            }
            catch (HibernateException hbex2)
            {
                StringBuffer exception = new StringBuffer ("Couldn't do rollback(): ");
                exception.append (hbex2.toString ());
                System.out.println (exception.toString ());
            }
            try
            {
                this.getSession ().close ();
            }
            catch (HibernateException hbex3)
            {
                StringBuffer exception = new StringBuffer ("Error clossing session!: ");
                exception.append (hbex3.toString ());
                System.out.println (exception.toString ());
            }
        }
    }
   
    public void end ()
    {
        if (this.getSession () != null)
            session.close ();
       
    }
}


the MediaManager invokes the Manager class on it's constructor and then uses it's methods.

Code:
public class MediaManager extends Manager
{
   
    private Session session;
    /** Creates a new instance of MediaManager */
    public MediaManager (Session session)
    {
        super (session);
    }
    public Media getMediaById (Long mediaId )
    {
        super.begin ();
        Media media = (Media) this.session.get (Media.class, mediaId);
        super.end ();
        return media;
    }
    public Set getUserUploadedMedia ()
    {
        Set topTen = null;
        Query hbQuery = null;
        try
        {
            /*Try to do as many operations as possible in a single transaction*/
            String queryString = new String ("from User usr where usr.email='xabier.burgos@gmail.com'");
            super.begin ();
            hbQuery = super.getSession ().createQuery (queryString);
            User cybrid = (User) hbQuery.uniqueResult ();
            topTen = cybrid.getUploadedMedia ();
            super.commit ();   
        }
        catch (QueryException queryEx)
        {
            System.out.println ("Error executing query: ");
            queryEx.printStackTrace (System.out);
            super.rollback ();
        }
        finally
        {
            super.end ();
        }
        return topTen;
    }
}


Full stack trace of any exception that occurs:
The could not execute batch update exception. Why is Hibernate trying to do an update when I'm just retrieving data?.

Code:
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
   org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
   org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
   org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
   org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:249)
   org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)
   org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
   org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
   org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
   org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
   org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
   org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
   com.mimetics.managers.Manager.commit(Manager.java:43)
   com.mimetics.managers.MediaManager.getTopTenMedia(MediaManager.java:50)
   com.mimetics.actions.Setup.execute(Setup.java:53)
   org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:53)
   org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:64)
   org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:48)
   org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
   org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
   org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
   org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:280)
   org.apache.struts.action.ActionServlet.process(ActionServlet.java:1858)
   org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:446)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
   org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)


Name and version of the database you are using: MySQL 5.0.27

The generated SQL (show_sql=true):

Code:
**** Initilizing HibernatePlugIn   **********
Using route to config file: file:/C:/Documents%20and%20Settings/Xabi/mediavault/build/web/WEB-INF/classes/hibernate.cfg.xml
AbandonedObjectPool is used (org.apache.tomcat.dbcp.dbcp.AbandonedObjectPool@954549)
   LogAbandoned: false
   RemoveAbandoned: true
   RemoveAbandonedTimeout: 300
*************************************
Hibernate: select user0_.email as email0_, user0_.name as name0_, user0_.surname as surname0_, user0_.country as country0_, user0_.nickname as nickname0_, user0_.password as password0_, user0_.preferences as preferen7_0_, user0_.type as type0_ from users user0_ where user0_.email='xabier.burgos@gmail.com'
Hibernate: select userprefer0_.preference_id as preference1_3_0_, userprefer0_.toolbar_order as toolbar2_3_0_, userprefer0_.rbar_order as rbar3_3_0_, userprefer0_.show_comments as show4_3_0_, userprefer0_.show_email as show5_3_0_ from user_preferences userprefer0_ where userprefer0_.preference_id=?
Hibernate: select usertype0_.type_id as type1_1_1_, usertype0_.type_name as type2_1_1_, usertype0_.privileges as privileges1_1_, userprivil1_.privilege_id as privilege1_2_0_, userprivil1_.convert_video as convert2_2_0_, userprivil1_.convert_audio as convert3_2_0_, userprivil1_.convert_image as convert4_2_0_, userprivil1_.conserve_files as conserve5_2_0_, userprivil1_.max_fsize as max6_2_0_, userprivil1_.can_send_msg as can7_2_0_ from user_types usertype0_ left outer join user_privileges userprivil1_ on usertype0_.privileges=userprivil1_.privilege_id where usertype0_.type_id=?
Hibernate: update user_privileges set convert_video=?, convert_audio=?, convert_image=?, conserve_files=?, max_fsize=?, can_send_msg=? where privilege_id=?


This is all the information I can provide, I'm not sure if I'm doing a wrong mapping or the problem is with the transaction or... Sry I'm a complete newbie :(

[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 04, 2007 9:26 am 
Newbie

Joined: Mon Mar 19, 2007 6:15 pm
Posts: 19
Location: Bilbao (Spain)
I'm still scratching my head with the question... why is hibernate doing an update?, I'm just trying to retrieve data from the set in the User POJO. I supouse all of this is my fault due to total inexperience with hibernate, but I'm unable to find a solution, and this is for my final proyect at university witch it's deadline is in a month... If someone could help me I would be very gratefull. Thanks in advance.


Top
 Profile  
 
 Post subject: Got new Information!!
PostPosted: Wed Apr 04, 2007 12:19 pm 
Newbie

Joined: Mon Mar 19, 2007 6:15 pm
Posts: 19
Location: Bilbao (Spain)
Now this is even stranger. I thought that the problem could be in the session's scope, so I removed all the <Managers> thing and just put the app logic directly into the Action so:

Code:
public class Setup extends Action
{
    private Set topTen = null;
    private SessionFactory sFactory = null;
   
    public ActionForward execute (ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception
    {
        ServletContext sCtx = request.getSession ().getServletContext ();
        sFactory = (SessionFactory) sCtx.getAttribute (HibernatePlugIn.SESSION_FACTORY_KEY);
        sFactory.getCurrentSession ().beginTransaction ();
     
        User cybrid = (User) sFactory.getCurrentSession ().createQuery ("from User usr where usr.email='xabier.burgos@gmail.com'").uniqueResult ();
        topTen = cybrid.getUploadedMedia ();
       
        sFactory.getCurrentSession ().getTransaction ().commit ();
       
        return (mapping.findForward ("setup.successfull"));
    }
}


As you can see the SessionFactory is retrieved from the ServletContext. SessionFactory has already been loaded via a Struts PlugIn.

Now the realy strange thing is that if I test the application one time I get the previous exception:

Code:
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update


Logical since Hibernate (for a strange reason I don't understand) is trying to do an update:

Code:
Hibernate: select user0_.email as email0_, user0_.name as name0_, user0_.surname as surname0_, user0_.country as country0_, user0_.nickname as nickname0_, user0_.password as password0_, user0_.preferences as preferen7_0_, user0_.type as type0_ from users user0_ where user0_.email='xabier.burgos@gmail.com'
Hibernate: select userprefer0_.preference_id as preference1_3_0_, userprefer0_.toolbar_order as toolbar2_3_0_, userprefer0_.rbar_order as rbar3_3_0_, userprefer0_.show_comments as show4_3_0_, userprefer0_.show_email as show5_3_0_ from user_preferences userprefer0_ where userprefer0_.preference_id=?
Hibernate: select usertype0_.type_id as type1_1_1_, usertype0_.type_name as type2_1_1_, usertype0_.privileges as privileges1_1_, userprivil1_.privilege_id as privilege1_2_0_, userprivil1_.convert_video as convert2_2_0_, userprivil1_.convert_audio as convert3_2_0_, userprivil1_.convert_image as convert4_2_0_, userprivil1_.conserve_files as conserve5_2_0_, userprivil1_.max_fsize as max6_2_0_, userprivil1_.can_send_msg as can7_2_0_ from user_types usertype0_ left outer join user_privileges userprivil1_ on usertype0_.privileges=userprivil1_.privilege_id where usertype0_.type_id=?
Hibernate: update user_privileges set convert_video=?, convert_audio=?, convert_image=?, conserve_files=?, max_fsize=?, can_send_msg=? where privilege_id=?


Buuuuut, if I run the app again a second time (runned from Netbeans not a normal reload "F5" in browser), Hibernate just does a normal Select and that's all:

Code:
Hibernate: select user0_.email as email0_, user0_.name as name0_, user0_.surname as surname0_, user0_.country as country0_, user0_.nickname as nickname0_, user0_.password as password0_, user0_.preferences as preferen7_0_, user0_.type as type0_ from users user0_ where user0_.email='xabier.burgos@gmail.com'


This is (at least for me) really really strange. Nobody has an idea of what may be going on?.

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 04, 2007 2:02 pm 
Newbie

Joined: Mon Mar 19, 2007 6:15 pm
Posts: 19
Location: Bilbao (Spain)
nobody?. Please I know begging is not ok, but I'm getting desperate :(


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 04, 2007 2:22 pm 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
It's hard to say exactly. Have you tried turing on debugging for the org.hibernate package? While that will give you a boatload of messages to look through, the debug log is extremely complete. It does not look like anything is misconfigured, but perhaps if you post the mappings for UserType and UserPriviledge (?) then it might provide a bit more insight.

I am a bit disconcerted by the storing of the SessionFactory in the httpSession, do you directly use the SessionFactory in your jsp's? Because Hibernate already has a facility to store the SessionFactory in a thread-bound manner (@see current_session_context_class).


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 04, 2007 2:36 pm 
Newbie

Joined: Mon Mar 19, 2007 6:15 pm
Posts: 19
Location: Bilbao (Spain)
First a million thanks for your response (I thought noone would/could help).

I didn't know of that facility, it's the first time in my life I use an ORM tool like hibernate , also I'm a bit "green" in all the J2EE stuff, and my project is using Struts, Velocity and Hibernate. I searched through the net for struts-hibernate integration and came up with the plugin solution.

Here I post you the Struts plugin and the mappings you have requested.

@UserType.hbm.xml
Code:
<hibernate-mapping auto-import="true" default-lazy="false">
   
    <!-- Indicamos la clase a persistir y la tabla a la que corresponde-->
    <class name="com.mimetics.beans.UserType" table="user_types">
       
        <!-- Especificamos la clave primaria -->
        <id name="userTypeId" type="integer" column="type_id">
            <generator class="native"/>
        </id>
       
        <!-- A continuación el resto de atributos -->
        <property name="userTypeName" type="string" column="type_name" not-null="true"/>
        <many-to-one name="userPrivileges" not-null="true" class="com.mimetics.beans.UserPrivileges"
                     foreign-key="FK_user_types_user_privileges" column="privileges" unique="true"/>
    </class>
</hibernate-mapping>


@UserPrivileges.hbm.xml
Code:
<hibernate-mapping auto-import="true" default-lazy="false">
   
    <!-- Indicamos la clase a persistir y la tabla a la que corresponde-->
    <class name="com.mimetics.beans.UserPrivileges" table="user_privileges">
       
        <!-- Especificamos la clave primaria -->
        <id name="privilegeId" type="integer" column="privilege_id">
            <generator class="native"/>
        </id>
       
        <!-- A continuación el resto de atributos -->
        <property name="convertVideo" type="boolean" column="convert_video" not-null="true"/>
        <property name="convertAudio" type="boolean" column="convert_audio" not-null="true"/>
        <property name="convertImage" type="boolean" column="convert_image" not-null="true"/>
        <property name="conserveFiles" type="boolean" column="conserve_files" not-null="true"/>
        <property name="maxFSize" type="long" column="max_fsize" not-null="true" />
        <property name="canSendMsg" type="boolean" column="can_send_msg"/>
    </class>
</hibernate-mapping>


@UserPreferences.hbm.xml
Code:
<hibernate-mapping auto-import="true" default-lazy="false"> 
    <class name="com.mimetics.beans.UserPreferences" table="user_preferences">       
        <id name="userPreferencesId" type="long" column="preference_id">
            <generator class="native"/>
        </id>
        <property name="toolboxOrder" type="string" not-null="true" column="toolbar_order"/>
        <property name="rbarOrder" type="string" not-null="true" column="rbar_order"/>
        <property name="showComments" type="boolean" not-null="true" column="show_comments"/>
        <property name="showEmail" type="boolean" not-null="true" column="show_email"/>
    </class>
</hibernate-mapping>


And the Struts PlugIn code:

Code:
public class HibernatePlugIn implements PlugIn
{
    /**
     * IMPORTANT NOTE!
     * For this to work the hibernate configuration file
     * MUST be located in /WEB-INF/classes or
     * you'll get a null pointer exception and neither
     * Hibernate or Struts will load.
     */
    private String _configFilePath = "/hibernate.cfg.xml";
   
    /**
     * the key under which the <code>SessionFactory</code> instance is stored
     * in the <code>ServletContext</code>.
     */
    public static final String SESSION_FACTORY_KEY
            = SessionFactory.class.getName ();
   
    private SessionFactory _factory = null;
   
    public void destroy ()
    {
        try
        {
            _factory.close ();
        }
        catch(HibernateException e)
        {
            System.out.println ("Unable to close Hibernate Session Factory: " + e.getMessage ());
        }
       
    }
   
    public void init (ActionServlet servlet, ModuleConfig config) throws ServletException
    {
        System.out.println ("*************************************");
        System.out.println ("**** Initilizing HibernatePlugIn   **********");
        Configuration configuration = null;
        URL configFileURL = null;
        ServletContext context = null;
       
        try
        {
            configFileURL = HibernatePlugIn.class.getResource (_configFilePath);
            System.out.println ("Using route to config file: "+configFileURL.toString ());
            context = servlet.getServletContext ();
           
            configuration = (new Configuration ()).configure (configFileURL);
            _factory = configuration.buildSessionFactory ();
            //Set the factory into session
            context.setAttribute (SESSION_FACTORY_KEY, _factory);
           
        }
        catch(HibernateException e)
        {
            System.out.println ("Error while initializing hibernate: ");
            e.printStackTrace (System.out);
        }
        catch(Exception ex)
        {
            System.out.println ("Something unexpected happened...");
            ex.printStackTrace (System.out);
        }
        System.out.println ("*************************************");
       
    }
   
    /**
     * Setter for property configFilePath.
     * @param configFilePath New value of property configFilePath.
     */
    public void setConfigFilePath (String configFilePath)
    {
        if ((configFilePath == null) || (configFilePath.trim ().length () == 0))
        {
            throw new IllegalArgumentException (
                    "configFilePath cannot be blank or null.");
        }
       
        System.out.println ("Setting 'configFilePath' to '"  + configFilePath + "'...");
        _configFilePath = configFilePath;
    }
   
   
/*(SessionFactory) servletContext.getAttribute
(HibernatePlugIn.SESSION_FACTORY_KEY);
*/
   
}


If you need something else just lettme know. And again a million thanks for the help :)

Edit:
I forgot to add the hibernate configuration file, just in case it has something wrong. I'm using Tomcat's 5.5 Connection poling along with hibernate.


Code:
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.datasource">java:/comp/env/jdbc/mediavault</property>
        <property name="hibernate.connection.pool_size">20</property>
        <property name="show_sql">true</property>
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="hibernate.hbm2ddl.auto">update</property>
        <property name="current_session_context_class">thread</property>
        <!-- List of mapping files go here -->
        <mapping resource="com/mimetics/beans/User.hbm.xml"/>
        <mapping resource="com/mimetics/beans/UserType.hbm.xml"/>
        <mapping resource="com/mimetics/beans/UserPrivileges.hbm.xml"/>
        <mapping resource="com/mimetics/beans/UserPreferences.hbm.xml"/>
        <mapping resource="com/mimetics/beans/Media.hbm.xml"/>
        <mapping resource="com/mimetics/beans/MediaType.hbm.xml"/>
        <mapping resource="com/mimetics/beans/Comment.hbm.xml"/>
        <mapping resource="com/mimetics/beans/Message.hbm.xml"/>
        <mapping resource="com/mimetics/beans/MessageType.hbm.xml"/>
    </session-factory>
</hibernate-configuration>
[/i]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 04, 2007 3:35 pm 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
I have to leave the office for a while, but I will take a look at your mappings this evening. Until then...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 04, 2007 7:08 pm 
Newbie

Joined: Mon Mar 19, 2007 6:15 pm
Posts: 19
Location: Bilbao (Spain)
Ok, understood, again a million thanks :D


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 05, 2007 10:36 am 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
Let's try a couple things first:

1) Let's make sure there is nothing in the SessionFactory before it is used in the action. Immediately after obtaining it, call clear() thusly:

Code:
public class Setup extends Action
{
    private Set topTen = null;
    private SessionFactory sFactory = null;
   
    public ActionForward execute (ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception
    {
        ServletContext sCtx = request.getSession ().getServletContext ();
        sFactory = (SessionFactory) sCtx.getAttribute (HibernatePlugIn.SESSION_FACTORY_KEY);
        sFactory.getCurrentSession().clear(); // make sure the current session is totally empty before proceeding
        sFactory.getCurrentSession ().beginTransaction ();
     
        User cybrid = (User) sFactory.getCurrentSession ().createQuery ("from User usr where usr.email='xabier.burgos@gmail.com'").uniqueResult ();
        topTen = cybrid.getUploadedMedia ();
       
        sFactory.getCurrentSession ().getTransaction ().commit ();
       
        return (mapping.findForward ("setup.successfull"));
    }
}


2) If that still produces the error, let's see the User*.java domain object classes, maybe a setter or getter is dirtying the UserPrivileges somewhere.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 05, 2007 12:12 pm 
Newbie

Joined: Mon Mar 19, 2007 6:15 pm
Posts: 19
Location: Bilbao (Spain)
Ok, I've tested it and two things happen:

1- Putting
Code:
sFactory.getCurrentSession().clear();

before begining a transaction I get a exception:
Code:
org.hibernate.HibernateException: clear is not valid without active transaction
   org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:297)
   $Proxy0.clear(Unknown Source)
   com.mimetics.actions.Setup.execute(Setup.java:44)
   org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:53)
   org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:64)
   org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:48)
   org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
   org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
   org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
   org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:280)
   org.apache.struts.action.ActionServlet.process(ActionServlet.java:1858)
   org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:446)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
   org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)


2- Putting
Code:
sFactory.getCurrentSession().clear();

after begining a transaction stills produces the
Code:
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
Exception.

Here are the POJO's for User.java, UserType.java, UserPrivileges.java and UserPreferences.java

@User.java
Code:
public class User implements Serializable
{
    private String email;       // Email address (used as primary key)
    private String name;        // Real name
    private String surname;     // Real surname
    private String password;    // Password
    private UserType userType;      // Type
    private UserPreferences userPreferences; //User defined preferences
    private String nickname;        // Nick, used to login
    private String country;     // Country
    private Long favorites;
    private Long groups;
    private Set uploadedMedia = new HashSet();
    private Set sentMessages = new HashSet();
    private Set receivedMessages = new HashSet();
    private Set postedComments = new HashSet();
   
    /** Creates a new instance of user */
    public User ()
    {
    }
    public User (String name, String surname, String password, UserType utype,
            UserPreferences upreferences, String nick, String country)
    {
        this.name = name;
        this.surname = surname;
        this.password = password;
        this.userType = utype;
        this.nickname = nick;
        this.country = country;
        this.email = email;
        this.userPreferences = upreferences;
        this.postedComments = new HashSet();
        this.receivedMessages = new HashSet();
        this.sentMessages = new HashSet();
        this.uploadedMedia = new HashSet();
    }
    //GET
    public String getName ()
    {
        return this.name;
    }
    public String getSurname ()
    {
        return this.surname;
    }
    public String getPassword ()
    {
        return this.password;
    }
    public UserType getUserType ()
    {
        return this.userType;
    }
    public String getNickname ()
    {
        return this.nickname;
    }
    public String getCountry ()
    {
        return this.country;
    }
    public String getEmail ()
    {
        return this.email;
    }
    public UserPreferences getUserPreferences ()
    {
        return this.userPreferences;
    }
    public Set getUploadedMedia ()
    {
        return this.uploadedMedia;
    }
    public Set getSentMessages ()
    {
        return this.sentMessages;
    }
    public Set getReceivedMessages ()
    {
        return this.receivedMessages;
    }
    public Set getPostedComments ()
    {
        return this.postedComments;
    }
    //SET
    public void setName (String name)
    {
        this.name = name;
    }
    public void setSurname (String surname)
    {
        this.surname = surname;
    }
    public void setPassword (String password)
    {
        this.password = password;
    }
    public void setUserType (UserType utype)
    {
        this.userType = utype;
    }
    public void setNickname (String nick)
    {
        this.nickname = nick;
    }
    public void setCountry (String country)
    {
        this.country = country;
    }
    public void setEmail (String email)
    {
        this.email = email;
    }
    public void setUserPreferences (UserPreferences upreferences)
    {
        this.userPreferences = upreferences;
    }
    public void setUploadedMedia (Set uploadedMedia)
    {
        this.uploadedMedia = uploadedMedia;
    }
    public void setSentMessages (Set sentMessages)
    {
        this.sentMessages = sentMessages;
    }
    public void setReceivedMessages (Set receivedMessages)
    {
        this.receivedMessages = receivedMessages;
    }
    public void setPostedComments (Set postedComments)
    {
        this.postedComments = postedComments;
    }
}


@UserType.java
Code:
package com.mimetics.beans;

/**
*
* @author cybrid
*/
public class UserType
{
      private Integer userTypeId;
      private String userTypeName;
      private UserPrivileges userPrivileges;
     
      /** Creates a new instance of UserType */
      public UserType ()
      {
      }
      public UserType (String userTypeName, UserPrivileges userPrivileges)
      {
            this.userTypeName = userTypeName;
            this.userPrivileges = userPrivileges;
      }
      //GET
      public Integer getUserTypeId ()
      {
            return this.userTypeId;
      }
      public String getUserTypeName ()
      {
            return this.userTypeName;
      }
      public UserPrivileges getUserPrivileges()
      {
          return this.userPrivileges;
      }
      //SET
      public void setUserTypeId (Integer userTypeId)
      {
            this.userTypeId = userTypeId;
      }
      public void setUserTypeName (String userTypeName)
      {
            this.userTypeName = userTypeName;
      }
      public void setUserPrivileges (UserPrivileges userPrivileges)
      {
          this.userPrivileges = userPrivileges;
      }
}


@UserPrivileges.java
Code:
public class UserPrivileges
{
    private Integer privilegeId;        // Identifier
    private Boolean convertVideo;        // Should user's files be converted?
    private Boolean convertAudio;
    private Boolean convertImage;
    private Boolean conserveFiles;
    private Long maxFSize;       // Maximum file size allowed to upload
    private Boolean canSendMsg;   // Can user send messages to other members?
   
    /** Creates a new instance of privileges */
    public UserPrivileges ()
    {
       
    }
   
    public UserPrivileges (Boolean convertVideo, Boolean convertAudio, Boolean convertImage,
            Boolean conserveFiles, Long maxFSize, Boolean canSendMsg)
    {
        this.convertAudio = convertAudio;
        this.convertVideo = convertVideo;
        this.convertImage = convertImage;
        this.conserveFiles = conserveFiles;
        this.maxFSize = maxFSize;
        this.canSendMsg = canSendMsg;
    }
    //GET
    public Integer  getPrivilegeId ()
    {
        return this.privilegeId;
    }
    public Boolean getConvertAudio ()
    {
        return this.convertAudio;
    }
    public Boolean getConvertVideo ()
    {
        return this.convertVideo;
    }
    public Boolean getConvertImage ()
    {
        return this.convertImage;
    }
    public Boolean getConserveFiles ()
    {
        return this.conserveFiles;
    }
    public Long  getMaxFSize ()
    {
        return this.maxFSize;
    }
    public Boolean getCanSendMsg ()
    {
        return this.canSendMsg;
    }
    //SET
    public void setPrivilegeId (Integer privilegeId)
    {
        this.privilegeId = privilegeId;
    }
    public void setConvertAudio (Boolean convertAudio)
    {
        this.convertAudio = convertAudio;
    }
    public void setConvertVideo (Boolean convertVideo)
    {
        this.convertVideo = convertVideo;
    }
    public void setConvertImage (Boolean convertImage)
    {
        this.convertImage = convertImage;
    }
    public void setConserveFiles (Boolean conserveFiles)
    {
        this.conserveFiles = conserveFiles;
    }
    public void setMaxFSize (Long maxFSize)
    {
        this.maxFSize = maxFSize;
    }
    public void setCanSendMsg (Boolean CanSendMsg)
    {
        this.canSendMsg = canSendMsg;
    }
}


@UserPreferences.java
Code:
package com.mimetics.beans;
/**
*
* @author cybrid
*/
public class UserPreferences
{
    private Long userPreferencesId;
    private String toolboxOrder;
    private String rbarOrder;
    private Boolean showEmail;
    private Boolean showComments;
   
    /** Creates a new instance of UserPreferences */
    public UserPreferences ()
    {
    }
    public UserPreferences (String toolboxOrder, String rbarOrder, Boolean showEmail, Boolean showComments)
    {
        this.toolboxOrder = toolboxOrder;
        this.rbarOrder = rbarOrder;
        this.showComments = showComments;
        this.showEmail = showEmail;
    }
   
    //GET
    public Long getUserPreferencesId()
    {
        return this.userPreferencesId;
    }
    public String getToolboxOrder ()
    {
        return this.toolboxOrder;
    }
    public String getRbarOrder ()
    {
        return this.rbarOrder;
    }
    public Boolean getShowComments ()
    {
        return this.showComments;
    }
    public boolean getShowEmail ()
    {
        return this.showEmail;
    }
    //SET
    public void setUserPreferencesId (Long userPreferencesId)
    {
        this.userPreferencesId = userPreferencesId;
    }
    public void setToolboxOrder (String toolboxOrder)
    {
        this.toolboxOrder = toolboxOrder;
    }
    public void setRbarOrder (String rbarOrder)
    {
        this.rbarOrder = rbarOrder;
    }
    public void setShowComments (Boolean showComments)
    {
        this.showComments = showComments;
    }
    public void setShowEmail (Boolean showEmail)
    {
        this.showEmail = showEmail;
    }
}


And finnaly the User.hbm.xml mapping file, just in case I didn't put it earlier.

@User.hbm.xml
Code:
<hibernate-mapping auto-import="true" default-lazy="false">   
    <class name="com.mimetics.beans.User" table="users">       
        <id name="email" type="string" column="email">
            <generator class="native"/>
        </id>
        <property name="name" type="string" column="name" not-null="true" length="45"/>
        <property name="surname" type="string" column="surname" not-null="true" length="45"/>
        <property name="country" type="string" column="country" not-null="true" length="255"/>
        <property name="nickname" type="string" column="nickname" not-null="true" length="45"/>
        <property name="password" type="string" column="password" not-null="true" length="12"/>
       
        <many-to-one name="userPreferences"  class="com.mimetics.beans.UserPreferences"
                     foreign-key="fk_user_user_preferences" column="preferences"  not-null="true" unique="true"/>
                     
        <many-to-one name="userType"  class="com.mimetics.beans.UserType"
                     foreign-key="fk_user_user_types" column="type"  not-null="true"/>
       
        <!-- Collection Sets -->
        <set name="uploadedMedia" lazy="true" inverse="true">
            <key  column="owner"/>
            <one-to-many class="com.mimetics.beans.Media"/>
        </set>
       
        <!-- SENT & RECEIVED MESSAGES -->
        <set name="sentMessages" table="messages" lazy="true" >
            <key not-null="true" column="from"/>
            <one-to-many class="com.mimetics.beans.Message"/>
        </set>
        <set name="receivedMessages" table="messages" lazy="true">
            <key not-null="true" column="to"/>
            <one-to-many class="com.mimetics.beans.Message"/>
        </set>
        <!-- POSTED COMMENTS -->
        <set name="postedComments" lazy="true">
            <key not-null="true" column="email"/>
            <one-to-many class="com.mimetics.beans.Comment" />
        </set>
    </class>
</hibernate-mapping>


If you have more ideas just tellme; I'll test them in no time. And again thanks, your help is unvaluable :)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 05, 2007 12:29 pm 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
Sorry for #1, I meant to put it after the transaction start, but must have fat fingered my ctrl-v.

A couple quickies: I assume that if you comment out
Code:
topTen = cybrid.getUploadedMedia ();
in the action that no exception occurs. You can remove the following from the User non-empty constructor, since it was already performed at the field level. I don't think that it would dirty the collection, as I would not anticipate this constructor being called by Hibernate.
Code:
        this.postedComments = new HashSet();
        this.receivedMessages = new HashSet();
        this.sentMessages = new HashSet();
        this.uploadedMedia = new HashSet();


edit: whoops, wrong mapping paths, ignore first suggestion.


Last edited by Ananasi on Thu Apr 05, 2007 12:55 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 05, 2007 12:54 pm 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
Just another quick thought. If you are using Java5, maybe the autoboxing/unboxing of the boolean -> Boolean properties are dirtying the entities. In your mapping for UserPrivileges, change the property types to java.lang.Boolean and see what happens. Might as well change long to java.lang.Long as well. e.g.

Code:
<hibernate-mapping auto-import="true" default-lazy="false">
   
    <!-- Indicamos la clase a persistir y la tabla a la que corresponde-->
    <class name="com.mimetics.beans.UserPrivileges" table="user_privileges">
       
        <!-- Especificamos la clave primaria -->
        <id name="privilegeId" type="integer" column="privilege_id">
            <generator class="native"/>
        </id>
       
        <!-- A continuación el resto de atributos -->
        <property name="convertVideo" type="java.lang.Boolean" column="convert_video" not-null="true"/>
        <property name="convertAudio" type="java.lang.Boolean" column="convert_audio" not-null="true"/>
        <property name="convertImage" type="java.lang.Boolean" column="convert_image" not-null="true"/>
        <property name="conserveFiles" type="java.lang.Boolean" column="conserve_files" not-null="true"/>
        <property name="maxFSize" type="java.lang.Long" column="max_fsize" not-null="true" />
        <property name="canSendMsg" type="java.lang.Boolean" column="can_send_msg"/>
    </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 05, 2007 1:38 pm 
Newbie

Joined: Mon Mar 19, 2007 6:15 pm
Posts: 19
Location: Bilbao (Spain)
One thing; it doesn't matter if I comment or uncomment cybrid.getUploadedMedia(); the exception goes on the "commit()".

Oh, and I tested changing the type properties to java.lang.Boolean and so, and nothing happens , I get the same exception.

This is freaking strange, don't you think?

Edit: Monitorizing MySQL with the myslq administrator tool, it realy notices a thread trying to update the database so it's totaly confirmed that hibernate is trying to update the table on the database.


Last edited by Cybrid on Thu Apr 05, 2007 1:43 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 05, 2007 1:42 pm 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
Ya, it is. I'd say it's time to start looking at debug logs, because your mappings and pojos look fine to me. Debug the entire org.hibernate package and post the piece that encapsulates the Action (if it's not enormous...could be).


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 05, 2007 1:54 pm 
Newbie

Joined: Mon Mar 19, 2007 6:15 pm
Posts: 19
Location: Bilbao (Spain)
Ok, I'll try debugging. I do not know how to debug hibernate but I'll try a "debugging hibernate with log4j" that I've found on the net. Also, I'm begining to think that it could be a Hibernate bug and updating from my current version (3.2.0) to 3.2.2 could solve it. What do you think?.

Edit: Made it!. Wooooooooah, these logs are huge, my fear it'll be a while till I find something that points out the problem.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 23 posts ]  Go to page 1, 2  Next

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.