If you need to select which columns need update when executing a CMP statement you might use the "updatable" attribute on the @Column annotation.
Setting "updatable" = false will assume that the column is not always included in the SQL update statement.

@Column(name="colname" updatable="false")

At the moment this feature is available only with TopLink JPA.

0
0
0
s2smodern

The FetchType strategy defines strategies for fetching data from the database. The EAGER strategy is a requirement on the persistence provider runtime that data must be eagerly fetched. The  LAZY strategy is a hint to the persistence provider runtime that data should be fetched lazily when it is first accessed. 

Here is how you can specify in your annotations the fetch strategy  (fetch = FetchType.LAZY)

@Entity
@Table(name = "PET")
public class Pet implements Serializable {
	private long id;

	private Zoo zoo;
	
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "ID")
	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name="ZOO_ID")
	public Zoo getZoo() {
		return zoo;
	}

	public void setZoo(Zoo zoo) {
		this.zoo = zoo;
	}
}


@Entity
@Table(name = "ZOO")
public class Zoo implements Serializable {
	private long id;
	
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "ID")
	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}
}
0
0
0
s2smodern

 

You can use the @Index annotation with EJB3 in Hibernate 3.2.X to create indexes automatically when an entity is deployed.
This annotation can be put either on the Table annotation or directly on the entity property.

Examples:

@javax.persistence.Table(name = "items")
@org.hibernate.annotations.Table(appliesTo = "items", indexes = { @Index(name = "INDX", columnNames = { "idItem" }) })

 

@Index(name = "IDX", columnNames = { "idItem" })
public String getIdItem() {
return timestamp;
}

 

 

0
0
0
s2smodern