我试图正确地建立不同实体之间的关系。
看着代码,我认为一切都是好的和连贯的(我已经验证了属性的名称与在Hibernate映射配置文件中建立的名称相同),但是,好吧,它没有编译。所以很明显这是不可以的。显示的错误如下:
org.springframework.beans.factory.BeanCreationException: Error creating
bean with name 'org.springframework.dao.annotation.
PersistenceExceptionTranslationPostProcessor#0' defined in class path
resource [spring.cfg.xml]: Initialization of bean failed; nested
exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'sessionFactory' defined in class path
resource [spring.cfg.xml]: Invocation of init method failed; nested
exception is org.hibernate.HibernateException: Unable to instantiate
default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.igalia.mswl</groupId>
<artifactId>snippr</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>snippr Maven Webapp</name>
<url>http://maven.apache.org</url>
<!-- =================================================================== -->
<!-- Default values for properties.These default values are expected to
be valid for most profiles.Specific profiles can overwrite values when necessary. -->
<properties>
<!-- Data source properties -->
<dataSource.user>test</dataSource.user>
<dataSource.password>test</dataSource.password>
<dataSource.jndiName>jdbc/testdb</dataSource.jndiName>
<testDataSource.user>${dataSource.user}</testDataSource.user>
<testDataSource.password>${dataSource.password}</testDataSource.password>
<org.springframework.version>3.0.5.RELEASE</org.springframework.version>
<spring-security.version>3.0.5.RELEASE</spring-security.version>
</properties>
<!-- =================================================================== -->
<!-- Profiles. * The build is always executed by selecting at least two
non-exclusive profiles. By default, such profiles are "dev" and "postgresql"
(meaning "use PostgreSQL assuming a development environment"). * General
profiles. There are two general (database-independent) profiles: "dev" and
"prod". The former is used for development (including testing) and the latter
is used for production (including testing). As shown below, two dataSources
(databases schemas) are used in both profiles: one for running (dataSource)
and another one for the Maven test fase (testDataSource). Note the Maven
test fase is executed both with development and production profiles. * Database-specific
profiles. There is a profile for each supported database. * Specific profiles
can be defined to better adapt to a particular environment by overwriting/adding
properties and/or including other chunks of valid XML. * Usage: + mvn <<goal>>
=> Execute <<goal>> with default profiles. + mvn -Pdev,<<database>> <<goal>
=> Execute <<goal>> with "dev" and <<database>> profiles. + mvn -Pprod,<<database>>
<<goal>> => Execute <<goal>> with "prod" and <<database>> profiles. + Note
that when using -P option all desired profiles must be specified (e.g. "-Pprod"
with the intention to select "prod" and the default database profile is not
correct; "-Pprod,<<database>>" must be used instead). * Examples: + mvn <<goal>>
+ mvn -Ppostgresql,prod <<goal>> + mvn -Ppostgresql,dev <<goal>> -->
<profiles>
<!-- Development profile -->
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<!-- SnippR environment properties -->
<snippr.mode>dev</snippr.mode>
<!-- Hibernate properties -->
<hibernate.show_sql>true</hibernate.show_sql>
<hibernate.format_sql>true</hibernate.format_sql>
<hibernate.use_sql_comments>true</hibernate.use_sql_comments>
<hibernate.hbm2ddl.auto>update</hibernate.hbm2ddl.auto>
</properties>
</profile>
<!-- MySQL profile -->
<profile>
<id>mysql</id>
<properties>
<!-- JDBC driver properties -->
<jdbcDriver.groupId>mysql</jdbcDriver.groupId>
<jdbcDriver.artifactId>mysql-connector-java</jdbcDriver.artifactId>
<jdbcDriver.version>5.0.5</jdbcDriver.version>
<jdbcDriver.className>com.mysql.jdbc.Driver</jdbcDriver.className>
<!-- Data source properties -->
<dataSource.url>jdbc:mysql://localhost/testdb</dataSource.url>
<!-- Hibernate properties -->
<hibernate.dialect>org.hibernate.dialect.MySQLInnoDBDialect</hibernate.dialect>
</properties>
</profile>
<!-- PostgreSQL profile -->
<profile>
<id>postgresql</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<!-- JDBC driver properties -->
<jdbcDriver.groupId>postgresql</jdbcDriver.groupId>
<jdbcDriver.artifactId>postgresql</jdbcDriver.artifactId>
<jdbcDriver.version>8.3-603.jdbc4</jdbcDriver.version>
<jdbcDriver.className>org.postgresql.Driver</jdbcDriver.className>
<!-- Data source properties -->
<dataSource.url>jdbc:postgresql://localhost/testdb</dataSource.url>
<!-- Hibernate properties -->
<hibernate.dialect>org.hibernate.dialect.PostgreSQLDialect</hibernate.dialect>
<!-- <databasetable.prefix>public.</databasetable.prefix> -->
</properties>
</profile>
</profiles>
<!-- =================================================================== -->
<!-- Repository management -->
<repositories>
<repository>
<id>zkoss</id>
<url>http://mavensync.zkoss.org/maven2/</url>
<releases>
<enabled>true</enabled>
</releases>
</repository>
<repository>
<id>central</id>
<url>http://repo1.maven.org/maven2</url>
<releases>
<enabled>true</enabled>
</releases>
</repository>
</repositories>
<!-- =================================================================== -->
<!-- Dependency management -->
<dependencies>
<!-- JUnit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.4</version>
<scope>test</scope>
</dependency>
<!-- Log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
<!-- ZK -->
<dependency>
<groupId>org.zkoss.zk</groupId>
<artifactId>zk</artifactId>
<version>5.0.11</version>
</dependency>
<dependency>
<groupId>org.zkoss.zk</groupId>
<artifactId>zul</artifactId>
<version>5.0.11</version>
</dependency>
<dependency>
<groupId>org.zkoss.zk</groupId>
<artifactId>zkplus</artifactId>
<version>5.0.11</version>
</dependency>
<dependency>
<groupId>org.zkoss.zk</groupId>
<artifactId>zkspring-core</artifactId>
<version>3.0</version>
</dependency>
<dependency>
<groupId>org.zkoss.zk</groupId>
<artifactId>zkspring-security</artifactId>
<version>3.0</version>
</dependency>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<!-- Hibernate -->
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jta_1.0.1B_spec</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.12.1.GA</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.6.5.Final</version>
</dependency>
<!-- AspectJ -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>1.5.4</version>
</dependency>
<!-- JDBC driver -->
<dependency>
<groupId>${jdbcDriver.groupId}</groupId>
<artifactId>${jdbcDriver.artifactId}</artifactId>
<version>${jdbcDriver.version}</version>
</dependency>
<!-- Spring Security -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>${spring-security.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>${spring-security.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>${spring-security.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-acl</artifactId>
<version>${spring-security.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
<version>${spring-security.version}</version>
</dependency>
</dependencies>
<build>
<finalName>snippr</finalName>
<!-- =============================================================== -->
<!-- Filtering -->
<resources>
<!-- Apply filtering to files matching the following expressions in src/main/resources. -->
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>*spring.cfg.xml</include>
<include>*hibernate.cfg.xml</include>
<include>jetty-env.xml</include>
</includes>
</resource>
<!-- Continue considering resources the files in src/main/resources, but
without applying filtering. -->
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<testResources>
<!-- Apply filtering to files matching the following expressions in src/test/resources. -->
<testResource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
<includes>
<include>*spring.cfg-test.xml</include>
<include>*hibernate.cfg-test.xml</include>
</includes>
</testResource>
<!-- Continue considering resources the files in src/test/resources, but
without applying filtering. -->
<testResource>
<directory>src/test/resources</directory>
</testResource>
</testResources>
<!-- Maven plugin -->
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<verbose>true</verbose>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.18</version>
<configuration>
<jettyEnvXml>target/classes/jetty-env.xml</jettyEnvXml>
<reload>manual</reload>
<stopPort>9966</stopPort>
<stopKey>stop</stopKey>
<!-- Log to the console. -->
<requestLog implementation="org.mortbay.jetty.NCSARequestLog">
<append>true</append>
</requestLog>
</configuration>
<dependencies>
<dependency>
<groupId>${jdbcDriver.groupId}</groupId>
<artifactId>${jdbcDriver.artifactId}</artifactId>
<version>${jdbcDriver.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.snippr.business.entities" default-access="field">
<!-- User -->
<class name="User" table="users">
<id name="id" access="property">
<generator class="native" />
</id>
<property name="firstName" column="first_name" />
<property name="lastName" column="last_name" />
<property name="username" column="user_name" unique="true" />
<property name="password" column="password" />
<property name="email" column="email" />
<property name="enabled" column="enabled" />
<property name="accountNonExpired" column="account_non_expired" />
<property name="credentialsNonExpired" column="credentials_non_expired" />
<property name="accountNonLocked" column="account_non_locked" />
<set name="roles" table="users_roles" lazy="false">
<key column="user_id" />
<many-to-many column="role_id" entity-name="org.snippr.business.entities.Role" />
</set>
<set name="snippets" inverse="true" cascade="all-delete-orphan" >
<key column="user_id" />
<one-to-many class="org.snippr.business.entities.Snippet" />
</set>
<set name="labels" inverse="true" cascade="all-delete-orphan" >
<key column="user_id" />
<one-to-many class="org.snippr.business.entities.Label" />
</set>
<set name="comments" inverse="true" cascade="all-delete-orphan" >
<key column="user_id" />
<one-to-many class="org.snippr.business.entities.Comment" />
</set>
</class>
<!-- Role -->
<class name="Role" table="roles">
<id name="id" access="property">
<generator class="native" />
</id>
<property name="roleName" column="role_name" />
</class>
<!-- Snippet -->
<class name="Snippet" table="snippet">
<id name="id" access="property">
<generator class="native" />
</id>
<property name="title" unique="true" />
<property name="description" />
<set name="snippetCodes" inverse="true" cascade="all-delete-orphan">
<key column="snippet_id" />
<one-to-many class="org.snippr.business.entities.SnippetCode" />
</set>
<many-to-one name="user" class="org.snippr.business.entities.User"
column="user_id" not-null="true" />
<many-to-one name="label" class="org.snippr.business.entities.Label"
column="label_id" not-null="true" />
</class>
<!-- SnippetCode -->
<class name="SnippetCode" table="snippet_code">
<id name="id" access="property">
<generator class="native" />
</id>
<property name="code" unique="false" type="text" />
<many-to-one name="snippet" class="org.snippr.business.entities.Snippet"
column="snippet_id" not-null="true" />
</class>
<!-- Label -->
<class name="Label" table="label">
<id name="id" access="property">
<generator class="native" />
</id>
<property name="name" unique="false" />
<many-to-one name="user" class="org.snippr.business.entities.User"
column="user_id" not-null="true" />
<set name="snippets" inverse="true" cascade="save-update">
<key column="label_id" />
<one-to-many class="org.snippr.business.entities.Snippet" />
</set>
</class>
<!-- Comment -->
<class name="Comment" table="comment">
<id name="id" access="property">
<generator class="native" />
</id>
<property name="text" column="text"/>
<property name="email" column="email"/>
<property name="url" column="url"/>
<many-to-one name="user" class="org.snippr.business.entities.User"
column="user_id" not-null="true" />
</class>
</hibernate-mapping>
任何Java专家都有能力看到这里发生的事情或给出任何线索?正如我所说的,我已经验证了名称属性,我没有看到任何错别字错误。
有时当您的类路径中没有javassist.jar时会出现此错误。就像你说的那样。确保您拥有类属性的所有getter和setter。
我对Hibernate Spring MVC有几个问题。这是我从控制器调用数据库实体的示例: 控制器 服务 数据库服务 带有命名查询的car服务 汽车储存库 汽车实体 @Table(name = "car ",catalog = "ATS ")公共类car实现java.io.Serializable { 车型(外键链接,一对多关系) 车队实体 收购实体 我正在使用maven和4.2.1.RELEA
我正在使用Hibernate和JPA注释来映射我的类。当hibernate尝试映射这个类时,我遇到了一个问题 我的Social alStat类是: 我得到了这个错误: 我猜发生这种情况是因为我试图映射到一个基本类,但@ElementCollection注释不应该解决这个问题吗? 我的item类如下所示:
虽然向量最适合程序性编程,但我想对它们使用< code>map函数。以下代码片段有效: 为什么标准库中没有这样的函数?(以及 )。有没有其他方法可以处理它?
问题内容: 我想用Hibernate映射超类中的通用字段。 我的母亲班是: 一个子类: 如您所见,我将覆盖value字段以指定要在数据库中使用的列。我的表ParameterValue由几列组成,每种类型对应一列。 但是hibernate抱怨: 好的,但是超类中getValue的良好配置是什么?(我在“需要帮助的地方”发表了评论) 问题答案: 我很确定您不能将单个Java属性映射到三个不同的列。您将
我的用户实体: 我的角色实体: 现在,在数据库中创建的相应中间表具有以下属性。
我不是JPA/Hibernate方面的专家,我真的不知道我试图实现的是不可能实现的还是我做错了,既然我预计是后者,这里就什么也不做了。 我有一个map ,我正试图将其持久化到一个表中,并遵循了这里描述的示例:使用JPA存储map 但随后我得到一个HibernateException:列值的STATE_MAP中的列类型错误。找到:bigint,应为:char(255) 当我将bigint更改为cha