schemaexport

Hibernate整合Spring后,如何使用SchemaExport生成数据库表

ⅰ亾dé卋堺 提交于 2019-12-05 07:06:23
SchemaExport 生成数据库表 一. Hibernate 原生状态 Configuration cfg = new Configuration().configure(); SchemaExport export = new SchemaExport(cfg); export.create(true, true); 二. Hibernate 整合 Spring 1. 使用 hibernate.cfg.xml 原生配置 hibernate.cfg.xml 同原生一样编写 在 Spring 主配置文件 applicationContext 中,引入 hibernate.cfg.xml 使用 SchemaExport 生成数据库表的代码同上一致。 Spring applicationContext.xml <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="configLocation" value="file:src/hibernate.cfg.xml"> </property> </bean> 2. 不使用 hibernate.cfg.xml, 在 Spring 的主配置文件

NHibernate SchemaExport and Configure() catch-22

喜夏-厌秋 提交于 2019-12-03 20:25:24
问题 I want to use DDD in a new project and model my classes first, then generate the database schema based on the class library. My plan is to do this with the NHibernate hbm2ddl tool SchemaExport . The problem is that I can't get the SchemaExport to work because of a weird catch-22 problem it puts me in. The SchemaExport requires a Configuration object that itself requires a valid NHibernate configuration file as well as a set of database mappings. The catch-22 here is that when I do the

NHibernate SchemaExport and Configure() catch-22

佐手、 提交于 2019-11-30 15:46:40
I want to use DDD in a new project and model my classes first, then generate the database schema based on the class library. My plan is to do this with the NHibernate hbm2ddl tool SchemaExport . The problem is that I can't get the SchemaExport to work because of a weird catch-22 problem it puts me in. The SchemaExport requires a Configuration object that itself requires a valid NHibernate configuration file as well as a set of database mappings. The catch-22 here is that when I do the Configure(), it complains "Could not determine the name of the table for entity 'MyEntity'; remove the 'table'

Setting string to be sql type of “varchar” instead of “nvarchar”

会有一股神秘感。 提交于 2019-11-29 09:28:05
I have the following mapping: public class LogEntryMap { public LogEntryMap() { Map.Id(x => x.Id).GeneratedBy.Identity(); Map(x => x.Context).CustomSqlType("varchar").Length(512); } } However, using SchemaExport to generate the database in SQL Server 2008, the script generated ignores the length so in effect it ends up being a varchar with length of 1: create table OV_SAC.dbo.[LogEntry] ( Id BIGINT IDENTITY NOT NULL, Context varchar null, primary key (Id) ) .CustomSqlType("varchar 512") throws an exception. And without defining the CustomSqlType , strings are mapped to nvarchar (which does

Setting string to be sql type of “varchar” instead of “nvarchar”

非 Y 不嫁゛ 提交于 2019-11-28 02:52:06
问题 I have the following mapping: public class LogEntryMap { public LogEntryMap() { Map.Id(x => x.Id).GeneratedBy.Identity(); Map(x => x.Context).CustomSqlType("varchar").Length(512); } } However, using SchemaExport to generate the database in SQL Server 2008, the script generated ignores the length so in effect it ends up being a varchar with length of 1: create table OV_SAC.dbo.[LogEntry] ( Id BIGINT IDENTITY NOT NULL, Context varchar null, primary key (Id) ) .CustomSqlType("varchar 512")