企业已注解是否已取消外汇登记证证不注解可以吗

当前位置: &
外商独资企业外汇登记证的英文
英文翻译foreign exchange registration certificates for fies&&&&wholly foreign-owned enterpr ...&&&& foreign cu ...&&&&registration&&&&exclusively foreign- overseas- solely fore ...&&&&wholly foreign owned enterprise&&&&wholly foreign-owned enterprises&&&&solely foreign owned economy&&&&solely foreign-funded operation&&&&wholly for wholly foreignowned venture&&&&wholly foreign-owned&&&&allow full foreign equity operation&&&&58.
indiv singl ...&&&&proprietorship&&&&individual bu sole proprietorship&&&&enterprise solely solely state-owned enterprise&&&&sole proprietorship&&&&wfoe wholly foreign owned enterprises&&&&enterprises wit foreign
foreig ...&&&&proprietorship&&&&proprieter's capital audit&&&&proprietorship&&&&foreign investment enterprise (fie)&&&&sole proprietor&&&&exports by foreign-invested enter-prises&&&&business management of investment by foreign tradesman
相邻词汇热门词汇
外商独资企业外汇登记证的英文翻译,外商独资企业外汇登记证英文怎么说,怎么用英语翻译外商独资企业外汇登记证,外商独资企业外汇登记证的英文意思,,,发音,例句,用法和解释由查查在线词典提供,版权所有违者必究。
&&&&&&&&&&&&&&&&
Copyright &
(京ICP备号)
All rights reservedspring @Resource注解的困惑使用@Resource注解,在jsp中不能获取。
我有一个公共类Page,交给spring管理
@Component
public&class&Page&{
Action&也交给spring管理
@Controller&@Scope("prototype")
public&class&TrainCheckTypeAction&extends&ActionSupport&&{
private&Page&
public&String&searchTypeByPage()&throws&Exception{
page&=&trainServiceImpl.getCheckTypeByPage(pageNo,&Constant.PAGE_SIZE);
在对应的jsp调用
${page.pageBar}&没有发现值&在&s:debug&中的Value&Stack&也看到page的变量
只能写page的get和set方法,难道@Resource在这里无效?
还有一个疑问就是Resource是不是只能用于类的注解?
回答1:@resource&应该是无效的
你加上get&&&set方法&应该是用了struts2的全局变量的原因所以才能在jsp里用${}取到值,这里估计跟spring的注解没什么关系的spring 注解事务不起作用(太奇怪了) - ITeye问答
CopyOfUserServiceImp.java
package com.
import java.sql.C
import java.sql.SQLE
import java.sql.S
import javax.sql.DataS
import org.springframework.transaction.annotation.T
public class CopyOfUserServiceImp implements UserService{
private DataSource dataS
@Transactional(readOnly=true)
public void addUser() {
Connection cn=dataSource.getConnection();
Statement st=cn.createStatement();
st.executeUpdate("insert into user(name,password) values('y','1')");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
//throw new UnsupportedOperationException();
public DataSource getDataSource() {
return dataS
public void setDataSource(DataSource dataSource) {
this.dataSource = dataS
applicationContext.xml
&?xml version="1.0" encoding="UTF-8"?&
&beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-2.5.xsd"&
&import resource="classpath:spring-generated-dao-context.xml"/&
&import resource="classpath:spring-dao-context.xml"/&
&import resource="classpath:spring-generated-security-context.xml"/&
&import resource="classpath:spring-security-context.xml"/&
&import resource="classpath:spring-generated-service-context.xml"/&
&import resource="classpath:spring-service-context.xml"/&
&bean id="dataSource" class="mons.dbcp.BasicDataSource" destroy-method="close"&
&property name="driverClassName" value="com.mysql.jdbc.Driver"/&
&property name="url" value="jdbc:mysql://localhost:3306/spring"/&
&property name="username" value="root"/&
&property name="password" value=""/&
&bean id="CopyOfUserServiceImp" class="com.zjhc.CopyOfUserServiceImp"&
&property name="dataSource" ref="dataSource"/&
&bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"&
&property name="dataSource" ref="dataSource"/&
&tx:annotation-driven transaction-manager="txManager"/&
package com.
import org.springframework.context.support.ClassPathXmlApplicationC
public class test {
public static void main(String args[])
ClassPathXmlApplicationContext factory = new ClassPathXmlApplicationContext("applicationContext.xml");
UserService usi = (UserService)factory.getBean("CopyOfUserServiceImp");
usi.addUser();
Uservice是CopyOfUserServiceImp的接口。
我刚开始用xml配置事务的时候(也就是 &tx:advice& &aop:config&这种形式),没有问题,会出现事务为只读无法插入数据。
但当我改成,在add方法上用注解声明
@Transactional(readOnly=true)
发现仍然可以执行insert,插入数据。太奇怪了。不知道哪里有点问题,我自己也折腾了好长时间。
问题补充:这样没有用。
问题补充:谢谢。试过,这个没有用。&div class="quote_title"&7454103 写道&/div&&div class="quote_div"&不对& 这个 类也需要
&br /&
&br /&@Transactional
&br /&public class CopyOfUserServiceImp implements UserService{&
&br /&
&br /&试试&&img src="/images/smiles/icon_wink.gif"/& &/div&
&br /&
问题补充:上传了元代码和配置文件,那个数据库的话,就一个表(user),id,name,password,3个字段。id是int 自动增长的。
问题补充:还是能插进去,而且我把代码稍微调整了下,先执行插入,再执行除零错。还是能插,奇了。&div class="quote_title"&xhliuangel 写道&/div&&div class="quote_div"&事务你只是选了只读了,只读只是一般用于查询记录的时候才使用的,你尝试一下以下这样的方法
&br /&
&br /&@Transactional(propagation = Propagation.REQUIRED)
&br /&&&& public void addUser() {&
&br /&&&&&&&&& try {&
&br /&&&&&&&&&&&& Connection cn=dataSource.getConnection();&
&br /&&&&&&&&&&&& Statement st=cn.createStatement();&
&br /&&&&&&&&&&&&&& int i =0;
&br /&&&&&&&&&&&& i = 5/0;
&br /&&&&&&&&&&&& st.executeUpdate("insert into user(name,password) values('y','1')");&
&br /&&&&&&&& } catch (SQLException e) {&
&br /&&&&&&&&&&&& // TODO Auto-generated catch block&
&br /&&&&&&&&&&&& e.printStackTrace();&
&br /&&&&&&&& }&
&br /&&&&&&&&& //throw new UnsupportedOperationException();&
&br /&&&& }&
&br /&
&br /&试试出错的时候时候有回滚,如果有回滚的话而且数据没有插入的话那证明事务起作用了&/div&
&br /&
下载次数: 60
采纳的答案
程序已经帮你调试通过了! 请联系我& 接受!
1.使用DataSourceUtils.getConnection(dataSource)来获得数据库连接。spring把开启事务的连接放在线程变量里了,dataSource.getConnection()重新取新的连接当然不行了。
2.mysql使用了哪个模式,可能数据库就不支持事务。检查log输出看看事务管理是否执行了。
事务你只是选了只读了,只读只是一般用于查询记录的时候才使用的,你尝试一下以下这样的方法
@Transactional(propagation = Propagation.REQUIRED)
&&& public void addUser() {&
&&&&&&&& try {&
&&&&&&&&&&& Connection cn=dataSource.getConnection();&
&&&&&&&&&&& Statement st=cn.createStatement();&
&&&&&&&&&&&&& int i =0;
&&&&&&&&&&& i = 5/0;
&&&&&&&&&&& st.executeUpdate("insert into user(name,password) values('y','1')");&
&&&&&&& } catch (SQLException e) {&
&&&&&&&&&&& // TODO Auto-generated catch block&
&&&&&&&&&&& e.printStackTrace();&
&&&&&&& }&
&&&&&&&& //throw new UnsupportedOperationException();&
试试出错的时候时候有回滚,如果有回滚的话而且数据没有插入的话那证明事务起作用了
吧你的项目 打包给我发一下
我本地调试下! 那个下载不了!
不对& 这个 类也需要
@Transactional
public class CopyOfUserServiceImp implements UserService{&
类上加@Service
已解决问题
未解决问题22876人阅读
一。实体Bean
每个持久化POJO类都是一个实体Bean,
通过在类的定义中使用
@Entity 注解来进行声明。
声明实体Bean
public class Flightimplements Serializable {
& public Long getId() { }
& public void setId(Long id) { this.id = }
注解将一个类声明为实体Bean, @Id
注解声明了该实体Bean的标识属性。
可以对类的属性或者方法进行注解。属性对应field类别,方法的getXxx()对应property类别。
@Table 为实体Bean指定对应数据库表,目录和schema的名字。
@Table(name=&tbl_sky&)
public class Skyimplements Serializable {
注解包含一个schema和一个catelog属性,使用@UniqueConstraints
可以定义表的唯一约束。
@Table(name=&tbl_sky&,
& uniqueConstraints ={@UniqueConstraint(columnNames={&month&, &day&})}
上述代码在&
&month& 和 &day&
两个 field
上加上unique constrainst.
注解用于支持乐观锁版本控制。
public class Flightimplements Serializable {
&& @Version
&& @Column(name=&OPTLOCK&)
&& public Integer getVersion() { ... }
version属性映射到 &OPTLOCK&
列,entity manager
使用这个字段来检测冲突。一般可以用数字或者 timestamp
类型来支持 version.
实体Bean中所有非static
非 transient
属性都可以被持久化,除非用@Transient注解。
默认情况下,所有属性都用
@Basic 注解。
//transient property
private S //persistent property
@Transient
StringgetLengthInMeter() { ... } //transient property
String getName() {...} // persistent property
int getLength() { ...} // persistent property
@Basic(fetch =FetchType.LAZY)
StringgetDetailedComment() { ... } // persistent property
@Temporal(TemporalType.TIME)
java.util.DategetDepartureTime() { ... } // persistent property
@Enumerated(EnumType.STRING)
Starred getNote() {... } //enum persisted as String in database
上述代码中counter, lengthInMeter
属性将忽略不被持久化,而firstname, name, length
被定义为可持久化和可获取的。
@TemporalType.(DATE,TIME,TIMESTAMP)分别Map java.sql.(Date,Time, Timestamp).
@Lob注解属性将被持久化为 Blog
类型。具体的java.sql.Clob, Character[], char[]
和 java.lang.String
将被持久化为 Clob
类型. java.sql.Blob,Byte[], byte[]
和 serializable type
将被持久化为 Blob
public StringgetFullText() {
&& return fullT& // clob type
public byte[]getFullCode() {
& return fullC& // blog type
注解将属性映射到列。
public class Flightimplements Serializable {
&& @Column(updatable = false, name =&flight_name&, nullable = false, length=50)
&& public String getName() { ... }
属性映射到 flight_name column, not null, can't update, length equal 50
&& name=&columnName&; (1)
&& boolean unique() (2)&&&
是否在该列上设置唯一约束
&& boolean nullable() (3)&&
&& boolean insertable() (4)
该列是否作为生成 insert语句的一个列
&& boolean updatable() (5)&
该列是否作为生成 update语句的一个列
&& String columnDefinition() default&&; (6)&
默认值
&& String table() default &&;(7)&&&&&&&&&&&&
定义对应的表(deault
&& int length() default 255; (8)&&&&&&&&&&&&&
&& int precision() default 0; // decimalprecision (9)& decimal精度
&& int scale() default 0; // decimal scale&&&&&&& (10)&decimal长度
嵌入式对象(又称组件)也就是别的对象定义的属性
组件类必须在类一级定义
@Embeddable 注解。在特定的实体关联属性上使用 @Embeddable
和 @AttributeOverride
注解可以覆盖该属性对应的嵌入式对象的列映射。
public class Personimplements Serializable {
&& // Persistent component using defaults
&& Address homeA
&& @Embedded
&& @AttributeOverrides( {
&&&&& @AttributeOverride(name=&iso2&,column = @Column(name=&bornIso2&) ),
&&&&& @AttributeOverride(name=&name&,column = @Column(name=&bornCountryName&) )
&& Country bornIn;
@Embeddable
public class Addressimplements Serializable {
&& C //no overriding here
@Embeddable
public class Countryimplements Serializable {
&& private String iso2;
&& @Column(name=&countryName&)private S
&& public String getIso2() { return iso2; }
&& public void setIso2(String iso2) { this.iso2= iso2; }
&& public String getName() { }
&& public void setName(String name) { this.name= }
类定义了 Address
Country 对象,具体两个类实现见上。
无注解属性默认值:
o属性为简单类型,则映射为@Basic
o属性对应的类型定义了@Embeddable
注解,则映射为@Embedded
o属性对应的类型实现了Serializable,则属性被映射为@Basic并在一个列中保存该对象的serialized版本。
o属性的类型为java.sql.Clob or java.sql.Blob,
则映射到 @Lob
对应的类型。
映射主键属性
注解可将实体Bean中某个属性定义为主键,使用@GenerateValue注解可以定义该标识符的生成策略。
可以是 identity column, sequence
或者 table
类型,取决于不同底层的数据库
使用table保存id值
o IDENTITY - identity column
o SEQUENCE - seque
@Id@GeneratedValue(strategy=GenerationType.SEQUENCE, generator=&SEQ_STORE&)
public Integer getId(){ ... }
@Id@GeneratedValue(strategy=GenerationType.IDENTITY)
public Long getId() {... }
生成器,适用与可移值的应用,多个@Id可以共享同一个identifier生成器,只要把generator属性设成相同的值就可以。通过@SequenceGenerator和@TableGenerator
可以配置不同的identifier
&table-generatorname=&EMP_GEN&
&&&& table=&GENERATOR_TABLE&
&&&& pk-column-name=&key&
&&&& value-column-name=&hi&
&&&& pk-column-value=&EMP&
&&&& allocation-size=&20&/&
//and the annotationequivalent
@javax.persistence.TableGenerator(
&&&& name=&EMP_GEN&,
&&&& table=&GENERATOR_TABLE&,
&&&& pkColumnName = &key&,
&&&& valueColumnName = &hi&
&&&& pkColumnValue=&EMP&,
&&&& allocationSize=20
&sequence-generatorname=&SEQ_GEN&
&&&& sequence-name=&my_sequence&
&&&& allocation-size=&20&/&
//and the annotationequivalent
@javax.persistence.SequenceGenerator(
&&&& name=&SEQ_GEN&,
&&&& sequenceName=&my_sequence&,
&&&& allocationSize=20
The next example showsthe definition of a sequence generator in a class scope:
@javax.persistence.SequenceGenerator(
&&& name=&SEQ_STORE&,
&&& sequenceName=&my_sequence&
public class Storeimplements Serializable {
&& private L
&& @Id@GeneratedValue(strategy=GenerationType.SEQUENCE,generator=&SEQ_STORE&)
&& public Long getId() { }
Store类使用名为my_sequence的sequence,并且SEQ_STORE生成器对于其他类是不可见的。
通过下面语法,你可以定义组合键。
o将组件类注解为@Embeddable,并将组件的属性注解为
o将组件的属性注解为@EmbeddedId
o将类注解为@IdClass,并将该实体中所有主键的属性都注解为 @Id
@IdClass(FootballerPk.class)
public classFootballer {
& //part of the id key
& @Id public String getFirstname() {
& public void setFirstname(String firstname) {
&&&& this.firstname =
& //part of the id key
& @Id public String getLastname() {
& public void setLastname(String lastname) {
&&& this.lastname =
& public String getClub() {
& public void setClub(String club) {
&& this.club =
& //appropriate equals() and hashCode()implementation
@Embeddable
public classFootballerPk implements Serializable {
& //same name and type as in Footballer
& public String getFirstname() {
& public void setFirstname(String firstname) {
&&& this.firstname =
& //same name and type as in Footballer
& public String getLastname() {
& public void setLastname(String lastname) {
&& this.lastname =
& //appropriate equals() and hashCode()implementation
@AssociationOverride(name=&id.channel&, joinColumns =@JoinColumn(name=&chan_id&) )
public class TvMagazin{
&& @EmbeddedId public TvMagazinP
&& @Temporal(TemporalType.TIME) D
@Embeddable
public class TvMagazinPkimplements Serializable {
&& @ManyToOne
&& public C
&& public S
&& @ManyToOne
&& public P
映射继承关系
EJB支持3种类型的继承。
o Table per Class Strategy: the &union-class& element inHibernate
每个类一张表
o Single Table per Class Hierarchy Strategy: the&subclass& element in Hibernate
每个类层次结构一张表
o Joined Subclass Strategy: the &joined-subclass&element in Hibernate
连接的子类策略
@Inheritance
注解来定义所选的之类策略。
每个类一张表
@Inheritance(strategy= InheritanceType.TABLE_PER_CLASS)
public class Flightimplements Serializable {
有缺点,如多态查询或关联。Hibernate使用 SQL Union
查询来实现这种策略。这种策略支持双向的一对多关联,但不支持IDENTIFY
生成器策略,因为ID必须在多个表间共享。一旦使用就不能使用AUTO和IDENTIFY生成器。
每个类层次结构一张表
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(
&&& name=&planetype&,
&&& discriminatorType=DiscriminatorType.STRING
@DiscriminatorValue(&Plane&)
public class Plane {... }
@DiscriminatorValue(&A320&)
public class A320extends Plane { ... }
整个层次结构中的所有父类和子类属性都映射到同一个表中,他们的实例通过一个辨别符列(discriminator)来区分。
是父类。@DiscriminatorColumn注解定义了辨别符列。对于继承层次结构中的每个类,
@DiscriminatorValue 注解指定了用来辨别该类的值。辨别符列名字默认为DTYPE,其默认值为实体名。其类型为DiscriminatorType.STRING。
连接的子类
@Inheritance(strategy=InheritanceType.JOINED)
public class Boatimplements Serializable { ... }
public class Ferryextends Boat { ... }
@PrimaryKeyJoinColumn(name=&BOAT_ID&)
public classAmericaCupClass extends Boat { ... }
以上所有实体使用JOINED
策略 Ferry和Boat class使用同名的主键关联(eg:Boat.id
= Ferry.id), AmericaCupClass
关联的条件为Boat.id = AmericaCupClass.BOAT_ID.
从父类继承的属性
@MappedSuperclass
public classBaseEntity {
& @Temporal(TemporalType.TIMESTAMP)
& public Date getLastUpdate() { ... }
& public String getLastUpdater() { ... }
@Entity class Orderextends BaseEntity {
& @Id public Integer getId() { ... }
继承父类的一些属性,但不用父类作为映射实体,这时候需要
@MappedSuperclass 注解。上述实体映射到数据库中的时候对应Order
其具有 id, lastUpdate, lastUpdater
三个属性。如果没有@MappedSuperclass
注解,则父类中属性忽略,这是Order
一个属性。
映射实体Bean的关联关系
@OneToOne 注解可以建立实体Bean之间的一对一关系。一对一关系有3种情况。
o关联的实体都共享同样的主键。
public class Body {
& public Long getId() { }
& @OneToOne(cascade = CascadeType.ALL)
& @PrimaryKeyJoinColumn
& public Heart getHeart() {
public class Heart {
& public Long getId() { ...}
通过@PrimaryKeyJoinColumn
注解定义了一对一的关联关系。
o其中一个实体通过外键关联到另一个实体的主键。注:一对一,则外键必须为唯一约束。
public class Customerimplements Serializable {
&& @OneToOne(cascade = CascadeType.ALL)
&& @JoinColumn(name=&passport_fk&)
&& public Passport getPassport() {
public class Passportimplements Serializable {
&& @OneToOne(mappedBy = &passport&)
&& public Customer getOwner() {
通过@JoinColumn注解定义一对一的关联关系。如果没有@JoinColumn注解,则系统自动处理,在主表中将创建连接列,列名为:主题的关联属性名
+ 下划线 +
被关联端的主键列名。上例为 passport_id,
因为Customer
中关联属性为passport, Passport
的主键为 id.
o通过关联表来保存两个实体之间的关联关系。注:一对一,则关联表每个外键都必须是唯一约束。
public class Customerimplements Serializable {
&& @OneToOne(cascade = CascadeType.ALL)
&& @JoinTable(name= &CustomerPassports&,
&&&&&&& joinColumns= @JoinColumn(name=&customer_fk&),
&&&&&&& inverseJoinColumns= @JoinColumn(name=&passport_fk&)
&& public Passport getPassport() {
@Entity public classPassport implements Serializable {
&& @OneToOne(mappedBy = &passport&)
&& public Customer getOwner() {
通过 CustomerPassports
关联表和 Passport
关联。该关联表通过passport_fk
外键指向Passport
表,该信心定义为inverseJoinColumns
的属性值。通过 customer_fk
外键指向Customer
表,该信息定义为joinColumns
属性值。
@ManyToOne 注解定义多对一关系。
public class Flightimplements Serializable {
& @ManyToOne( cascade = {CascadeType.PERSIST,CascadeType.MERGE} )
& @JoinColumn(name=&COMP_ID&)
& public Company getCompany() {
其中@JoinColumn
注解是可选的,关键字段默认值和一对一关联的情况相似。列名为:主题的关联属性名 +
下划线 +
被关联端的主键列名。本例中为company_id,因为关联的属性是company,Company的主键为
@ManyToOne
注解有个targetEntity属性,该参数定义了目标实体名。通常不需要定义,大部分情况为默认值。但下面这种情况则需要 targetEntity
定义(使用接口作为返回值,而不是常用的实体)。
public class Flightimplements Serializable {
&& @ManyToOne(cascade=&&{CascadeType.PERSIST,CascadeType.MERGE},targetEntity= CompanyImpl.class)
&& @JoinColumn(name=&COMP_ID&)
&& public Company getCompany() {
public interfaceCompany {
多对一也可以通过关联表的方式来映射,通过 @JoinTable
注解可定义关联表。该关联表包含指回实体的外键(通过@JoinTable.joinColumns)以及指向目标实体表的外键(通过@JoinTable.inverseJoinColumns).
public class Flightimplements Serializable {
@ManyToOne( cascade = {CascadeType.PERSIST,CascadeType.MERGE} )
&& @JoinTable(name=&Flight_Company&,
&&&&&& joinColumns =@JoinColumn(name=&FLIGHT_ID&),
&&&&&& inverseJoinColumns =@JoinColumn(name=&COMP_ID&)
&& public Company getCompany() {
@OneToMany
注解可定义一对多关联。一对多关联可以是双向的。
规范中多对一端几乎总是双向关联中的主体(owner)端,而一对多的关联注解为 @OneToMany(mappedBy=)
public class Troop {
& @OneToMany(mappedBy=&troop&)
& public Set&Soldier& getSoldiers() {
public class Soldier {
& @ManyToOne
& @JoinColumn(name=&troop_fk&)
& public Troop getTroop() {
通过troop属性和Soldier建立了一对多的双向关联。在 mappedBy
端不必也不能定义任何物理映射。
public class Customerimplements Serializable {
&& @OneToMany(cascade=CascadeType.ALL,fetch=FetchType.EAGER)
&& @JoinColumn(name=&CUST_ID&)
&& public Set&Ticket& getTickets() {
public class Ticketimplements Serializable {
&& ... //no bidir
一般通过连接表来实现这种关联,可以通过@JoinColumn注解来描述这种单向关联关系。上例 Customer
通过 CUST_ID列和 Ticket
建立了单向关联关系。
通过关联表来处理单向关联
public class Trainer {
& @OneToMany
& @JoinTable(
&&&& name=&TrainedMonkeys&,
&&&& joinColumns = @JoinColumn(name=&trainer_id&),
&&&& inverseJoinColumns = @JoinColumn(name=&monkey_id&)
& public Set&Monkey& getTrainedMonkeys(){
public class Monkey {
& ... //no bidir
通过关联表来处理单向一对多关系是首选,这种关联通过 @JoinTable
注解来进行描述。上例子中Trainer
通过TrainedMonkeys表和Monkey建立了单向关联关系。其中外键trainer_id关联到Trainer(joinColumns)而外键monkey_id关联到Monkey(inverseJoinColumns).
默认处理机制
通过连接表来建立单向一对多关联不需要描述任何物理映射,表名由一下3个部分组成,主表(ownertable)表名
+ 下划线 +
从表(the other side table)表名。指向主表的外键名:主表表名+下划线+主表主键列名指向从表的外键定义为唯一约束,用来表示一对多的关联关系。
public class Trainer {
& @OneToMany
& public Set&Tiger& getTrainedTigers(){
public class Tiger {
& ... //no bidir
上述例子中Trainer
通过 Trainer_Tiger
连接表建立单向关联关系。其中外键 trainer_id
关联到Trainer表,而外键
trainedTigers_id
关联到Tiger 表。
通过 @ManyToMany
注解定义多对多关系,同时通过 @JoinTable
注解描述关联表和关联条件。其中一端定义为owner,
另一段定义为inverse(对关联表进行更新操作,这段被忽略)。
public class Employerimplements Serializable {
& @ManyToMany(
&&&targetEntity=org.hibernate.test.metadata.manytomany.Employee.class,
&&& cascade={CascadeType.PERSIST,CascadeType.MERGE}
& @JoinTable(
&&& name=&EMPLOYER_EMPLOYEE&,
&&&joinColumns=@JoinColumn(name=&EMPER_ID&),
&&&inverseJoinColumns=@JoinColumn(name=&EMPEE_ID&)
& public Collection getEmployees() {
public class Employeeimplements Serializable {
& @ManyToMany(
&&& cascade = {CascadeType.PERSIST,CascadeType.MERGE},
&&& mappedBy = &employees&,
&&& targetEntity = Employer.class
& public Collection getEmployers() {
默认值:
关联表名:主表表名 +
下划线 +
从表表名;关联表到主表的外键:主表表名 +
下划线 +
主表中主键列名;关联表到从表的外键名:主表中用于关联的属性名 +
下划线 +
从表的主键列名。
用cascading
实现传播持久化(Transitivepersistence)
属性接受值为 CascadeType
数组,其类型如下:
CascadeType.PERSIST:cascades the persist (create) operation to associated entities persist() iscalled or if the entity is managed
如果一个实体是受管状态,或者当 persist()
函数被调用时,触发级联创建(create)操作。
CascadeType.MERGE:cascades the merge operation to associated entities if merge() is called or ifthe entity is managed
如果一个实体是受管状态,或者当merge()
函数被调用时,触发级联合并(merge)操作。
CascadeType.REMOVE:cascades the remove operation to associated entities if delete() is called
当 delete()
函数被调用时,触发级联删除(remove)操作。
CascadeType.REFRESH:cascades the refresh operation to associated entities if refresh() iscalled&
当 refresh()
函数被调用时,出发级联更新(refresh)操作。
CascadeType.ALL:all of the above& 以上全部
映射二级列表
使用类一级的
@SecondaryTable 和 @SecondaryTables
注解可以实现单个实体到多个表的映射。使用
@Column或者@JoinColumn
注解中的table
参数可以指定某个列所属的特定表。
@Table(name=&MainCat&)
@SecondaryTables({
&&& @SecondaryTable(name=&Cat1&,pkJoinColumns={
&&&&&&&&&&@PrimaryKeyJoinColumn(name=&cat_id&,referencedColumnName=&id&)}),
&&& @SecondaryTable(name=&Cat2&,uniqueConstraints={
&&&&&&&&&&@UniqueConstraint(columnNames={&storyPart2&})})
public class Catimplements Serializable {
& private I
& private S
private String storyPart1;
& private String storyPart2;
& @Id @GeneratedValue
& public Integer getId() {
& public String getName() {
& @Column(table=&Cat1&)
& public String getStoryPart1() {
&&& return storyPart1;
& @Column(table=&Cat2&)
& public String getStoryPart2() {
&&& return storyPart2;
上述例子中,name
保存在MainCat
表中,storyPart1保存在 Cat1
表中,storyPart2保存在Cat2
表中。Cat1
表通过外键cat_id
和 MainCat
表关联, Cat2
列和 MainCat
表关联。对storyPart2列还定义了唯一约束。
使用注解可以映射EJBQL/HQL
查询,@NamedQuery和 @NamedQueries
是可以使用在类级别或者JPA的XML文件中的注解。
&entity-mappings&
&&named-queryname=&plane.getAll&&
& &query&select p from Planep&/query&
&&/named-query&
&/entity-mappings&
@NamedQuery(name=&night.moreRecentThan&,query=&select n from Night n where n.date &= :date&)
public class Night {
public class MyDao {
&doStuff() {
&& Query q =s.getNamedQuery(&night.moreRecentThan&);
&& q.setDate( &date&, aMonthAgo );
&& List results = q.list();
可以通过定义QueryHint
数组的hints
属性为查询提供一些hint
信息。下图是一些Hibernate hints:
映射本地化查询
通过@SqlResultSetMapping
注解来描述 SQL
的 resultset
结构。如果定义多个结果集映射,则用 @SqlResultSetMappings。
@NamedNativeQuery(name=&night&area&,query=&select night.id nid, night.night_duration, &
&&&& + & night.night_date, area.id aid,night.area_id, area.name &
&&&& + &from Night night, Area area wherenight.area_id = area.id&, resultSetMapping=&joinMapping&)
@SqlResultSetMapping(name=&joinMapping&, entities={
&@EntityResult(entityClass=org.hibernate.test.annotations.query.Night.class,fields = {
&& @FieldResult(name=&id&,column=&nid&),
&& @FieldResult(name=&duration&,column=&night_duration&),
&& @FieldResult(name=&date&,column=&night_date&),
&& @FieldResult(name=&area&,column=&area_id&),
&& discriminatorColumn=&disc&
&@EntityResult(entityClass=org.hibernate.test.annotations.query.Area.class,fields = {
&& @FieldResult(name=&id&,column=&aid&),
&& @FieldResult(name=&name&,column=&name&)
上面的例子,名为“night&area”的查询和
&joinMapping&结果集映射对应,该映射返回两个实体,分别为 Night
其中每个属性都和一个列关联,列名通过查询获取。
@SqlResultSetMapping(name=&implicit&,
& entities=@EntityResult(
&&&entityClass=org.hibernate.test.annotations.@NamedNativeQuery(
&&&&& name=&implicitSample&,query=&select * from SpaceShip&,
&&&&& resultSetMapping=&implicit&)
public class SpaceShip{
&private S
&private S
&public String getName() {
&public void setName(String name) {
& this.name =
&@Column(name=&model_txt&)
&public String getModel() {
&public void setModel(String model) {
& this.model =
&public double getSpeed() {
&public void setSpeed(double speed) {
& this.speed =
上例中model1
属性绑定到model_txt
列,如果和相关实体关联设计到组合主键,那么应该使用
@FieldResult 注解来定义每个外键列。@FieldResult的名字组成:定义这种关系的属性名字 +&.& +
主键名或主键列或主键属性。
@SqlResultSetMapping(name=&compositekey&,
&entities=@EntityResult(entityClass=org.hibernate.test.annotations.query.SpaceShip.class,
& fields = {
&& @FieldResult(name=&name&, column =&name&),
&& @FieldResult(name=&model&, column= &model&),
&& @FieldResult(name=&speed&, column= &speed&),
&& @FieldResult(name=&captain.firstname&,column = &firstn&),
&&@FieldResult(name=&captain.lastname&, column =&lastn&),
&&@FieldResult(name=&dimensions.length&, column =&length&),
&&@FieldResult(name=&dimensions.width&, column =&width&)
&columns = { @ColumnResult(name =&surface&),
@ColumnResult(name =&volume&) } )
&@NamedNativeQuery(name=&compositekey&,
&query=&select name, model, speed, lnameas lastn, fname as firstn, length, width, length * width asresultSetMapping=&compositekey&)
如果查询返回的是单个实体,或者打算用系统默认的映射,这种情况下可以不使用 resultSetMapping,而使用resultClass属性,例如:
@NamedNativeQuery(name=&implicitSample&, query=&select * fromSpaceShip&,
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&resultClass=SpaceShip.class)
public class SpaceShip{
独有的注解扩展
提供了与其自身特性想吻合的注解,org.hibernate.annotations package包含了这些注解。
org.hibernate.annotations.Entity定义了&
Hibernate 实体需要的信息。
mutable: whetherthis entity is mutable or not& 此实体是否可变
dynamicInsert:allow dynamic SQL for inserts&& 用动态SQL新增
dynamicUpdate: allow dynamic SQL forupdates&& 用动态SQL更新
selectBeforeUpdate: Specifies thatHibernate should never perform an SQL UPDATE unless it is certain that anobject is actually modified.指明Hibernate从不运行SQL
Update,除非能确定对象已经被修改
polymorphism:whether the entity polymorphism is of PolymorphismType.IMPLICIT (default) orPolymorphismType.EXPLICIT
指出实体多态是PolymorphismType.IMPLICIT(默认)还是PolymorphismType.EXPLICIT
optimisticLock:optimistic locking strategy (OptimisticLockType.VERSION, OptimisticLockType.NONE,OptimisticLockType.DIRTY or OptimisticLockType.ALL)
乐观锁策略
@org.hibernate.annotations.GenericGenerator和@org.hibernate.annotations.GenericGenerators允许你定义hibernate特有的标识符。
@Id@GeneratedValue(generator=&system-uuid&)
@GenericGenerator(name=&system-uuid&,strategy = &uuid&)
public String getId(){
@Id@GeneratedValue(generator=&hibseq&)
@GenericGenerator(name=&hibseq&,strategy = &seqhilo&,
&& parameters = {
&&&& @Parameter(name=&max_lo&, value= &5&),
&&&& @Parameter(name=&sequence&,value=&heybabyhey&)
public Integer getId(){
@GenericGenerators(
& @GenericGenerator(
&& name=&hibseq&,
&& strategy = &seqhilo&,
&& parameters = {
&&& @Parameter(name=&max_lo&, value =&5&),
&&& @Parameter(name=&sequence&, value=&heybabyhey&)
& @GenericGenerator(...)
@NaturalId 注解标识
让数据库而不是JVM进行计算。
@Formula(&obj_length* obj_height * obj_width&)
public longgetObjectVolume()
通过在列属性(property)上使用@Index注解,可以指定特定列的索引,columnNames属性(attribute)将随之被忽略。
@Column(secondaryTable=&Cat1&)
@Index(name=&story1index&)
public StringgetStoryPart1() {
& return storyPart1;
@DiscriminatorFormula(&casewhen forest_type is null then 0 else forest_type end&)
public class Forest {... }
&&相关文章推荐
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:26315次
排名:千里之外}

我要回帖

更多关于 外汇登记证取消了吗 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信