How can I find/set the Assembly Name for Web Site created in Visual Web Developer?
Actually I am trying out NHibernate with Visual Web Developer Web site. In the .hbm.xml (mapping file) contains a attribute called Assembly where we need to specify the Assembly Name of the Project containing the entity class.
Where can I find the assembly name for the Web Site?
If a assembly name not available for a web site, how can I overcome this situation?
Update: If I omit the assembly attribute, I am getting error telling me that the assembly attribute is missing.
Product.hbm.xml:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="NHibernateSol.Domain" assembly="NHibernateSol1">
<class name="Product" >
<id name="Id">
<!-- generator class="guid" / -->
</id>
<property name="Name" />
<property name="Category" />
<property name="Discontinued" />
</class>
</hibernate-mapping>
System.Reflection.Assembly.GetAssembly(typeof(A_Class_Name_Here)).GetName().Name;
Related
I am trying to apply a persistence framework to an eclipse rcp e4 application. For this purpose, I created an example of a feature project, almost following the tutorial https://www.vogella.com/tutorials/JavaPersistenceAPI/article.html, but adapting for rcp. However I got the error "Persistence provider for EntityManager named xxx not found". I have searched for a week but found no solution. Could someone please tell me, what the error really is and how to resolve it?
The persistence.xml is located in project tasks.model folder META-INF. The eclipse.jar and javax.persistence.jar are in another plugin project (Earlier I defined maven dependencies in pom.xml. Although eclipse reports no compilation errors, but running rcp product would result in an error that ClassDefNotFoundException for persistence, so putting javax.persistence.jar in a separate plugin removed this error). Some answers suggested that the persistence.xml should be in the folder src/resources/META-INF. But in a plugin project the folder META-INF is already in its default place. I even created an extra folder resources/META-INF and put the persistence.xml in that, but it did not help. If I created a normal maven project, then things work properly, also when I change the database to mysql in localhost. The errors appear when I convert the project into a plugin project for building rcp applications.
The error "No Persistence provider for EntityManager" occurs when I invoke the command:
factory = Persistence.createEntityManagerFactory("todos");
My persistence.xml file looks like:
<?xml version="1.0" encoding="UTF-8" ?>
<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" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="todos" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>tasks.model.Todo</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver" />
<property name="javax.persistence.jdbc.url" value="jdbc:derby:/tempGeo/simpleDB" />
<property name="javax.persistence.jdbc.user" value="test" />
<property name="javax.persistence.jdbc.password" value="test" />
<!-- EclipseLink should create the database schema automatically -->
<property name="eclipselink.ddl-generation" value="create-tables" />
<property name="eclipselink.ddl-generation.output-mode" value="database" />
</properties>
</persistence-unit>
</persistence>
While deploying my jpa project to wildfly server i am gettings following warning:
The collection of metamodel types is empty.
Model classes may not have been found during entity
search for Java SE and some Java EE container managed persistence units.
Please verify that your entity classes are referenced in persistence.xml using
either <class> elements or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element
My persistence xml looks like this
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence" version="2.1">
<persistence-unit name="primary" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>java:jboss/datasources/example</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
<property name="javax.persistence.schema-generation.create-source" value="metadata"/>
<property name="javax.persistence.schema-generation.drop-source" value="metadata"/>
<property name="eclipselink.target-server" value="JBoss"/>
<property name="eclipselink.weaving" value="static"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost/example"/>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="javax.persistence.jdbc.password" value="xxx"/>
</properties>
</persistence-unit>
</persistence>
My Database tables are not created due to this.
Please help me understand this problem. As i am not able to understand the root cause of this.
For people who would come across this question like I did: I've just met this issue in Eclipse 2020-06 when running JPA Tools > Generate Tables from Entities, which is a situation probably different from the one in the question albeit with a strictly identical error message.
It turns out that the only thing needed to work around it is to hit Project > Clean and select the JPA project in the list.
For some unknown reason in my case, cleaning the project is necessary between runs of the Generate Tables command. I can't figure out why but that's the way it is. HTH
I'm currently trying to use nhibernate with MVC 3.5.
I have placed my nhibernate.cfg.xml in my root to my MVC project.
Please see screen grab of project. Both xml files are set to Embedded Resource.
I have a DeviceRepository.cs That has a method that uses Device.cs for the persistence.
Here is the xml of nhibernate.cfg.xml
<!-- properties -->
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.MySqlDataDriver</property>
<property name="connection.connection_string">Server=192.168.1.5;Database=imed_development;User ID=root;Password=lights337</property>
<property name="dialect">NHibernate.Dialect.MySQL5Dialect</property>
<!-- mapping files -->
<mapping resource="iMed.Models.Device.hbm.xml" assembly="iMed" />
Here is the xml of Device.hbm.xml
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="iMed.Models.Device" table="devices">
<id name="Id" column="ID" type="int">
<generator class="native"></generator>
</id>
<property name="Identifier" column="identifier" type="String"></property>
</class>
</hibernate-mapping>
I'm currently getting a
{"Could not compile the mapping document: iMed.Models.Device.hbm.xml"}
{"persistent class iMed.Models.Device not found"}
I'm pretty new to this, any input would be greatly appreciated...
Thanks in advance...
Patrick
its saying you are referencing a class in your mapping that doesn't exist.
I'm working with the Datanucleus tutorial application for JDO, specifically this one.
Regardless which "inheritance strategy" I try the table layout is the same. I would like two tables, one for PRODUCT and one for BOOK, but using the configuration below I only get the PRODUCT table with columns for both class Product and class Book.
<class name="Product" identity-type="sequence">
<inheritance strategy="complete-table"/>
<field name="name">
<column name="PRODUCT_NAME" length="100" jdbc-type="VARCHAR"/>
</field>
<field name="description">
<column length="255" jdbc-type="VARCHAR"/>
</field>
</class>
<class name="Book" identity-type="sequence">
<field name="author">
<column length="40" jdbc-type="VARCHAR"/>
</field>
<field name="isbn">
<column length="20" jdbc-type="CHAR"/>
</field>
<field name="publisher">
<column length="40" jdbc-type="VARCHAR"/>
</field>
</class>
The directory structure is exactly as in the tutorial, as is the build.xml. I have tried generating the schema via both the Ant task and the command line.
I use the sequence of commands:
ant clean
ant compile
ant enhance
ant createschema
The schema is generated but not as the Datanucleus documentation suggests that it should be with inheritance strategy "compete-table."
My target database is PostgreSQL 8.4 running on Ubuntu 10.04 if that matters.
Anyone else run into this issue and found a solution?
To answer my own question:
In the datanucleus tutorial download, the build.xml file given has a "createschema" target like:
<target name="createschema">
...
<schematool ...>
<fileset dir="${basedir}/target/classes">
<include name="**/*.class"/>
</fileset>
...
</schematool>
</target>
It should be changed to include all .jdo files as shown below:
<target name="createschema">
...
<schematool ...>
<fileset dir="${basedir}/target/classes">
<include name="**/*.class"/>
<include name="**/*.jdo"/>
</fileset>
...
</schematool>
</target>
In addition the package-hsql.orm file needs to be renamed to package-hsql.jdo and its header needs to be changed to:
<?xml version="1.0"?>
<!DOCTYPE jdo PUBLIC
"-//Sun Microsystems, Inc.//DTD Java Data Objects ORM Metadata 2.0//EN"
"http://java.sun.com/dtd/orm_2_0.dtd">
<jdo>
...
<jdo>
Notice that the DOCTYPE and root element were changed. The root element was "orm" and changed to "jdo".
Once I made these changes the schema generation tool followed the "inheritance strategy" directive.
For my custom application, I had a similar issue, and it worked fine after making the changes in the header of the jdo file. I am using version 3.2.9.
I've read in this post that all the ProxyFactory dependency was removed by using an interface in this post.
So you need to specify which implementation to use in the hibernate.cfg.xml file.
I've this configuration:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.connection_string">Data Source=.\SQLEXPRESS;Initial Catalog=MYDB;Integrated Security=true</property>
<property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
<property name='proxyfactory.factory_class'>NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
</session-factory>
</hibernate-configuration>
I've added a refernce to the NHibernate.ByteCode.Castle.dll. When I run the test using MBunit, I get the error that my deployment folder should contain either NHibernate.ByteCode.Castle.dll or NHibernate.ByteCode.LinFu.dll. I guess this is right configuration and it should work. But it is not working. I've spent much time behind this.
P.S: When I donwloaded NHibernate, the NHibernate.ByteCode.Castle project was not built. I added the project to the solution and built it. Then I referenced the assembly.
I had this same situation not too long ago.
When you say you added a reference, was it to the actual project or test project? It should be within both. Also, ensure "Copy Local" is set to true in the properties(F4) of the reference.
Another approach I took to check that if dll is within the directory that the application is running from was by calling the following prior to any of the Configuration.
Console.WriteLine(Directory.GetCurrentDirectory());
In my situation, I learned that when using ReSharper to execute tests, it was running in a location different than I had expected and was not containing the dll. Doing a Clean Solution and rebuilding seemed to correct the issue.
Hope this gives you a couple of things to check.