hbm

Java -- 在Eclipse上使用Hibernate

天大地大妈咪最大 提交于 2020-04-08 06:31:31
最近一个项目要用Java做,一点都不熟啊。没办法,只好硬着头皮啃了,花了大半天的时间,终于在Eclipse上完成了第一个Hibernate例子。下面记录关键的步骤,权作笔记,以备日后查看。 (1)下载Hibernate,并向项目中导入Hibernate。 Project->Properies->Java Build Path->Libraries->Add External JARs...,选择Hibernate根目录下的hibernate3.jar,添加到项目中。 接着,要将Hibernate下的lib文件夹下的所有文件都作为一个User Library添加到项目中,否则,如果仅仅添加hibernate3.jar,编译可以通过,运行却会抛出ClassNotDef的异常,因为hibernate3.jar依赖于Hibernate下的lib文件夹下的文件。 2)我们的应用的后台数据库使用的是Oracle,所以首先要在例子项目中引入含有Oracle jdbc driver的包,classes12.jar。该jar文件位于oracle安装目录的jdbc\lib目录下。 在Eclipse中,Project->Properies->Java Build Path->Libraries->Add External JARs...,选择classes12.jar,将其添加到项目中。 (3

Hibernate学习——映射关系

痞子三分冷 提交于 2020-03-23 05:28:53
学习记录 O(∩_∩)O 、 如果你恰巧路过,希望你能停下脚步瞧一瞧,不足之处望指出,感激不尽~ 使用工具 : 1、eclipse 2、hibernate压缩包(hibernate_4.3.11) 3、mysql 准备工作: 创建工程——>导入hibernate.jar包——>编写 hibernate.cfg.xml 配置文件 连接数据库 编写一个类读取hibernate.cfg.xml 一、单向一对多(例子:一个部门有多个员工) 1、建表(Employee员工表和dpet部门表) ①Employee类 ② 配置Employee.hbm.xml 映射文件,并在hibernate.cfg.xml文件中注册( <mapping resource="com/sw/entity/Employee.hbm.xml"/>) ③ Dept类 ④ Dept.hbm.xml配置文件,并在hibernate.cfg.xml文件中注册( <mapping resource="com/sw/entity/Dept.hbm.xml"/>) ⑤、创建表方法 2、添加数据: 先添加多端数据,再添加一端数据,再让多端中的数据与一端数据进行关联,在数据库中,会先执行insert语句,再执行update语句修改关联关系,效率偏低 来源: https://www.cnblogs.com/lady-Mu/p

hibernate4-hbm.xml基本使用-Maven Demo

限于喜欢 提交于 2020-03-01 15:13:57
目录结构如图, 1.用MyEclipse建立一个Maven-Java项目,然后给出pom配置, <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/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.xuebaosoft.hibernate4</groupId> <artifactId>hibernate4-maven-conf</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>hibernate4-maven-conf</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <

Hibernate Save Object without one column

扶醉桌前 提交于 2020-01-06 02:20:54
问题 I have a table called test and It has columns like id, name, address. I have created POJO class( User ) for all the three columns and same has been mapped with hbm configuration. Here My questions is, How do I prevent one column while saving the User object in session ( session.save(User) ). Let say I dont want to save my address field. How can I prevent. Are there any properties in HIbernate configuration or any modifier needs to be added in POJO? 回答1: Make that field as Transient. Transient

Set creation and update time with Hibernate in Xml mappings

淺唱寂寞╮ 提交于 2020-01-02 04:23:09
问题 I'm using Hibernate with Xml mappings. I have an entity that has two fields creationDate and updateDate of type timestamp , that have to be filled with the current UTC time when the entity is persisted and updated. I know about the existence of the @PrePersist and @PreUpdate annotations, but i don't know how to use their equivalent in my Xml mappings. Again, i was wondering if Hibernate somehow supports natively the update and creation time set. Thanks 回答1: I know about the existence of the

could not delete collection : [NHibernate.Exceptions.GenericADOException]

帅比萌擦擦* 提交于 2019-12-22 04:28:16
问题 I have Two Table , tableA and tableB. tableA have column : tabAId, col2, col3 (tabAId primaryKey and Identity column.) tableB have column : tabAId, name (tabAId is not null) I have create Bag in hbm file of tableA, to maintain relation ship. <bag name="tableB" lazy="true" inverse="false" batch-size="25" cascade="all-delete-orphan"> <key column="tabAId" /> <one-to-many class="tableB" /> </bag> When I try to update record in tableA it throw exception, where as I have list of child in tableA

failed.org.hibernate.MappingException: Could not determine type for: String, for columns: [org.hibernate.mapping.Column(db col name)

旧巷老猫 提交于 2019-12-20 01:39:44
问题 I am using Net Beans IDE , When i start to deploy my web project it shows me at the console output an error says: failed.org.hibernate.MappingException: Could not determine type for: String, for columns: [org.hibernate.mapping.Column(db col name) From the message it can not convert types ; I tried to check the types in my files .hbm and .java but no luck so far . The property for which this error is being thrown is defined as <property name="exemptionOwnerName1" type="String"> 回答1: The reason

Fluent NHibernate (1.2.0.712) export mappings to HBM not working / not respecting conventions

↘锁芯ラ 提交于 2019-12-19 10:26:57
问题 The HBM export function in Fluent NHibernate does not seem to work. If I call FluentMappingsContainer.ExportTo, the generated mappings come out incorrect, and I get the following exception: FluentNHibernate.Cfg.FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail. My configuration code looks like this: MsSqlConfiguration database = MsSqlConfiguration.MsSql2008

Breaking changes with NHibernate 4 upgrade

我们两清 提交于 2019-12-19 03:45:20
问题 I can see what's new and fixed in NHibernate 4.0 I would like to know if anyone has had issue with hbm mappings upgrading from NHibernate 3 to 4? I fear that more focus is going on fluent mapping these days. I can test for the more obvious breaking changes but wanted to know if there were any subtle issues that anyone has come across in a production environment that may not be so obvious at first. It looks like a major upgrade and you'd expect there to be the risk of regressions. 回答1: I

由代码生成数据库结构,保障设计正常传递到实现

给你一囗甜甜゛ 提交于 2019-12-14 10:51:55
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 我们常常使用代码生成工具来生成表结构。为什么不试试从代码来生成数据库表结构呢? 这个观点有些匪夷所思,但是熟悉Hibernate的同志应该有所体会。Hibernate有一个功能,叫做hbm2ddl,在系统启动时,Hibernate扫描hbm映射文件,检查数据库结构和hbm是否匹配,如果不匹配,则在数据库中增加hbm文件中描述的表或者字段。严格意义上来说,这不是从“代码”生成表结构,而是由“hbm配置文件”生成表结构。后来,当Hibernate支持注解功能后,hbm2ddl也会自动扫描EntityBean上的注解,来与数据库表结构进行匹配。所以,这个hbm2ddl,也算作从代码生成表结构。 回到原点,为什么需要从代码生成表结构的功能? 我们一般的开发过程,是先做了“数据库设计”,然后在数据库中建表,最后再编写java代码。数据库设计工具,一般提供生成表结构到数据库的功能,也提供生成和表结构对应的javabean功能。 【数据库】<-【数据库设计工具】->【JavaBean】 如果我们的数据库一次成型,永不改变,每个版本只做代码层面业务逻辑上的变动,那么上面的过程是比较完美的。 但实际上,作为一个长期维护的软件系统,数据库设计不变动,是几乎不可能的。那么,当开发下一个版本的时候,我们首先需要变动的是数据库设计文件