Page 1 of 1

ClassNotFoundException - Custom Entity

Posted: Thu Jun 12, 2014 6:33 am
by gowthamgutha
I am getting ClassNotFoundException for my custom entity which I created in the core module. I have listed that class in the blPu persistence unit as well as added it to the applicationContext.xml in the core module of the site by defining

Code: Select all

<bean id="org.broadleafcommerce.core.catalog.domain.Product" class="com.mycompany.core.catalog.domain.MyProductImpl" scope="prototype"/>


and also added a context:component-scan in the same applicationContext like this..

Code: Select all

<context:component-scan base-package="com.mycompany.core.catalog.domain"/>


I have also added the same in the applicationContext-entity.xml in the core module.

Code: Select all

<context:component-scan base-package="com.mycompany.core.catalog.domain"/>       
<bean id="org.broadleafcommerce.core.catalog.domain.Product" class="com.mycompany.core.catalog.domain.MyProductImpl" scope="prototype"/>


The class exists in the src/main of the core module as com.mycompany.core.catalog.domain

Thanks in advance.

Re: ClassNotFoundException - Custom Entity

Posted: Thu Jun 12, 2014 7:35 am
by RapidTransit
It doesn't matter which xml file in the core you put it in, the naming is there so you don't end up with big unwieldy xml configs, in your applicationContext.xml delete

Code: Select all

<bean id="org.broadleafcommerce.core.catalog.domain.Product" class="com.mycompany.core.catalog.domain.MyProductImpl" scope="prototype"/>


In your core you should look under resources/META-INF/persistence.xml

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
             version="2.0">
             
    <persistence-unit name="blPU" transaction-type="RESOURCE_LOCAL">
        <non-jta-data-source>jdbc/web</non-jta-data-source>
        <exclude-unlisted-classes/>

    </persistence-unit>
   
    <persistence-unit name="blSecurePU" transaction-type="RESOURCE_LOCAL">
        <non-jta-data-source>jdbc/webSecure</non-jta-data-source>
        <exclude-unlisted-classes/>

    </persistence-unit>

    <persistence-unit name="blCMSStorage" transaction-type="RESOURCE_LOCAL">
        <non-jta-data-source>jdbc/cmsStorage</non-jta-data-source>
        <exclude-unlisted-classes/>

    </persistence-unit>
</persistence>


Change it to look like this:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
             version="2.0">
             
    <persistence-unit name="blPU" transaction-type="RESOURCE_LOCAL">
        <non-jta-data-source>jdbc/web</non-jta-data-source>
        <class>com.mycompany.core.catalog.domain.MyProductImpl</class>
        <exclude-unlisted-classes/>

    </persistence-unit>
   
    <persistence-unit name="blSecurePU" transaction-type="RESOURCE_LOCAL">
        <non-jta-data-source>jdbc/webSecure</non-jta-data-source>
        <exclude-unlisted-classes/>

    </persistence-unit>

    <persistence-unit name="blCMSStorage" transaction-type="RESOURCE_LOCAL">
        <non-jta-data-source>jdbc/cmsStorage</non-jta-data-source>
        <exclude-unlisted-classes/>

    </persistence-unit>
</persistence>


Code: Select all

    <persistence-unit name="blPU" transaction-type="RESOURCE_LOCAL">
        <non-jta-data-source>jdbc/web</non-jta-data-source>

        <!---  ADD ENTITY CLASSES HERE --->

        <exclude-unlisted-classes/>

    </persistence-unit>

Re: ClassNotFoundException - Custom Entity

Posted: Thu Jun 12, 2014 12:21 pm
by gowthamgutha
I tried as you said but still I am getting the same error.

Do I have to modify any thing in the core/src/main/resources/applicationContext-entity.xml and core/src/main/resources/applicationContext.xml besides the persistence.xml

My core/src/main/resources/META-INF/persistence.xml is as follows

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
             version="2.0">
             
    <persistence-unit name="blPU" transaction-type="RESOURCE_LOCAL">
        <non-jta-data-source>jdbc/web</non-jta-data-source>
       <class>com.mycompany.core.catalog.domain.MyProductImpl</class>
    <exclude-unlisted-classes/>
    <properties>
     <property name="hibernate.hbm2ddl.auto" value="update" />
     <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
     <property name="hibernate.show_sql" value="true"/>
     <property name="hibernate.cache.use_second_level_cache" value="true"/>
     <property name="hibernate.cache.use_query_cache" value="true"/>
     <property name="hibernate.hbm2ddl.import_files" value="/sql/import_storage.sql"/>
   </properties>

    </persistence-unit>   
    <persistence-unit name="blSecurePU" transaction-type="RESOURCE_LOCAL">
        <non-jta-data-source>jdbc/webSecure</non-jta-data-source>
        <exclude-unlisted-classes/>
              <properties>
     <property name="hibernate.hbm2ddl.auto" value="update" />
     <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
     <property name="hibernate.show_sql" value="true"/>
     <property name="hibernate.cache.use_second_level_cache" value="true"/>
     <property name="hibernate.cache.use_query_cache" value="true"/>
     <property name="hibernate.hbm2ddl.import_files" value="/sql/import_storage.sql"/>
     </properties>
    </persistence-unit>

    <persistence-unit name="blCMSStorage" transaction-type="RESOURCE_LOCAL">
        <non-jta-data-source>jdbc/cmsStorage</non-jta-data-source>
        <exclude-unlisted-classes/>
              <properties>
     <property name="hibernate.hbm2ddl.auto" value="update" />
     <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
     <property name="hibernate.show_sql" value="true"/>
     <property name="hibernate.cache.use_second_level_cache" value="true"/>
     <property name="hibernate.cache.use_query_cache" value="true"/>
     <property name="hibernate.hbm2ddl.import_files" value="/sql/import_storage.sql"/>
        </properties>
    </persistence-unit>
</persistence>

Re: ClassNotFoundException - Custom Entity

Posted: Thu Jun 12, 2014 4:35 pm
by phillipuniverse
I am going to assume that you are not using Jrebel and that you are just starting back up with ant jetty-demo-jrebel. In that case, you will need to do a full Maven re-install from the root so that Maven will build the core jar again that the site project uses. When the war is built from ant jetty-demo-jrebel, it simply looks in your local maven repo for the core jar artifact. If that local maven repo is out of date, then it will use the out of date jar.

Let us know if that resolves your issue.

Re: ClassNotFoundException - Custom Entity

Posted: Fri Jun 13, 2014 12:53 am
by gowthamgutha
Previously, I have used JRebel and now my license has expired, So I am continuing with just the jetty-demo.
Also, I have seen once, that my ant tab was empty, I added build files again and then executed.

Do I have to re-install maven, if so is my eclipse-workspace will be cleaned? Do I need to back it up somewhere else?

Re: ClassNotFoundException - Custom Entity

Posted: Fri Jun 13, 2014 5:36 am
by gowthamgutha
When I hit the following in the url bar, which looks something like this..

http://localhost:8081/admin/com.mycompany.core.catalog.domain.MyProductImpl

I am getting the following error.

Code: Select all

org.broadleafcommerce.common.exception.ServiceException: Unable to fetch results for com.mycompany.core.catalog.domain.MyProductImpl


Caused by

Code: Select all

java.lang.IllegalStateException: Class didn't match - this should not occur


Thanks in advance.