This FAQ addresses frequently asked questions relating to TopLink,
the industry's most advanced object-to-relational persistence architecture.
It provides a highly flexible and productive mechanism for storing Java
objects and Enterprise Java Beans (EJBs) in relational database tables.
TopLink offers developers excellent performance and choice, working
with any database, any application server, any development toolset and
process, and any J2EE architecture.
TopLink is thethe industry's most advanced object-to-relational
persistence framework. It provides a highly flexible and productive
mechanism for storing Java objects and Enterprise Java Beans (EJBs)
in relational database tables. TopLink offers developers excellent
performance and choice, working with:
any database
any application server
any development toolset and process, and
any J2EE architecture.
With release 10.1.3, TopLink includes support for mapping objects
to XML documents and to legacy systems.
What
does TopLink cost? How is it licensed?
Under the OTN license, TopLink is free to download for evaluation
and use during development. A production license is included with
all editions of OracleAS or can be licensed separately for $5K per
CPU.
Is TopLink an application
or EJB server?
TopLink is neither an application nor an EJB server—it is
a pure Java class library. Because TopLink is certified 100% Pure
Java, it is capable of running within any certified Java environment.
With the enterprise classes, TopLink integrates with application
and EJB servers. TopLink also provides container-managed persistence
(CMP) for Entity Beans in Oracle Application Server Containers for
J2EE (OC4J), IBM WebSphere, and BEA WebLogic.
TopLink runtime library (called the Foundation Library)
Development tool: TopLink Workbench
Runtime tool: Web Client
What Java types does
TopLink support?
For relational database, TopLink automatically converts values
to and from the following Java types:
java.lang: Boolean, Float, Integer, String, Double, Long, Short,
Byte, Byte[ ], Character, Character[ ]; all the primitives associated
with these classes
java.math: BigInteger, BigDecimal
java.sql: Date, Time, Timestamp
java.util: Date, Calendar
For other Java types, you must use an object-type, type conversion,
or transformation mapping; or transform the value in the direct-to-field
get/set methods. Refer to Simple
Type Translator for information on supported Java types supported
in XML mapping.
What databases does
TopLink support?
TopLink can communicate with any relational database that has a
JDBC-compliant driver available such as Oracle, IBM Universal Database,
IBM Informix, IBM Cloudscape, Microsoft SQL Server, Microsoft Access,
and Sybase Adaptive Server. TopLink supports both the JDBC 1.x and
2.0 standards.
What kind of
Java objects does TopLink support (e.g., Java Objects, EJBs, JavaBeans)?
TopLink supports persistence for Plain Old Java Objects (POJOs)
and JavaBeans, EJB bean managed persistence (BMP) in any app server,
and container-managed persistence (CMP) for Entity Beans in Oracle
Application Server Containers for J2EE (OC4J), IBM WebSphere, and
BEA WebLogic.
What architectures
does TopLink support (e.g., J2EE, EJB, JSP)?
TopLink is architecture neutral. It does not dictate how you architect
your application and has been used in thousands of applications
using J2SE, J2EE, EJB, JSP, Struts, etc.
Can I use TopLink
Foundation Library in my application server?
TopLink Foundation Library can run in any application server running
in a Java Virtual Machine (JVM). You can use regular Java objects
or integrate with bean-managed persistence (BMP) Entity Beans. You
need the TopLink container persistence (CMP) Foundation Libraries
if you are going to use TopLink with CMP Entity Beans on Oracle
Application Server Containers for J2EE (OC4J), BEA WebLogic, or
IBM WebSphere application servers.
With EJB 2.x and 3.0,
do I still need TopLink?
Yes. The EJB 2.x and 3.0 specifications define two types of persistence
mechanisms for Entity Beans: container managed persistence (CMP)
and bean managed persistence (BMP). But the specification is just
that—a specification and not an implementation. TopLink provides
an implementation of CMP for the Oracle Application Server Containers
for J2EE (OC4J), BEA WebLogic, and IBM WebSphere application servers.
TopLink can also be used for BMP in any EBJ server.
Does
TopLink work in a multithreaded environment?
TopLink is 100% thread safe and can be used in JSP/Servlet or EJB
applications that require thread safety.
Where can I find demos?
A number of demos can be found on the TopLink
Demos page on OTN. Extensive examples are also included with
the TopLink distribution download accessible from the TopLink
page on OTN.
Is there a TopLink user forum?
Yes. The TopLink
Forum on OTN is very active with participation from both TopLink
users and members of the TopLink engineering team.
Does TopLink have a GUI
for mapping? Do I have to use it?
Yes, TopLink does have mapping tools and no, you don't have to
use them. Mapping tools are integrated into JDeveloper and also
available in the stand-alone TopLink Workbench. They provide a great
productivy boost over hand editing XML deployment descriptor files
or coding directly on the TopLink Foundation Library API. The TopLink
mapping tools identify problems in your mappings so that you don't
have to run your code to discover you've made and error. Tracking
down a mapping problem on a large project with 100's of XML mapping
files is not a trivial task. The TopLink mapping tools make O/R
mappings manageble.
Does TopLink perform
code generation to persist objects?
Because TopLink uses a metadata architecture, it does not need
to generate any code to enable your application's persistence.
TopLink can generate:
The TopLink project and associated descriptors into a single
Java class that, when compiled, can be used in place of the runtime
deployment XML file.
A table creator Java class that when compiled can create all
the tables on the database with required constraints.
Source code for the classes defined in the project.
Java object model, EJB-CMP EntityBean model, and EJB-BMP EntityBean
model from an existing database schema.
TopLink does generate classes for EJB2.0 CMP.
Does TopLink
require me to subclass a special class or implement a special interface?
TopLink does not force a developer to subclass from one of its
classes or use special types to maintain relationships. You could
build a domain model to map persistently that has no dependencies
on TopLink.
In an interview given to The Server Side, TopLink architect Mike
Keith answered this question by saying:
TopLink has always made extensive use of reflection. We have also
always claimed that execution in a reflection-based architecture
is no slower than non-reflection-based products, as long as the
reflection artifacts can be cached. This has proven to be true and
other products have also backed this claim up. In fact anybody that
does a quick benchmark of reflective method invocation or field
access can see similar results.
How does TopLink
support Oracle's grid computing initiative?
TopLink allows applications to be developed and enhanced flexibly,
to fit into a service-oriented architecture. By enabling loose coupling
between the application and persistent data, TopLink helps developers
optimize their applications for the grid. In addition, TopLink provides
crucial persistent functionality used in applications and other
Oracle development frameworks.
Does TopLink comply with
the JDO (JSR-012) specification?
No, TopLink does not implement the complete JDO 1.0 specification.
Although support for some of the JDO API was provided in past releases
of TopLink, this API is deprecated in 10.1.3 and will be removed
in a future release.
How do I configure
my environment to work with TopLink?
After installing TopLink, you must configure your development system
to use the TopLink classes, as well as allow TopLink to access the
core Java classes, Java virtual machine (JVM), and your domain classes.
Refer to
Using an Integrated Development Environment and
Using TopLink Workbench for details. The MetaLink
Knowledge Base also contains detailed information. In general
you must:
Ensure that a valid JVM exists in your path.
Ensure that the TopLink Foundation classes (toplink.jar) are
in your classpath.
Ensure that all domain classes, that you will want to map persistently
using TopLink, are included in your classpath.
Ensure that the path to your JDBC driver classes are included
in your classpath.
What additional functionality
is available in the TopLink container-managed persistence (CMP) Foundation
Libraries?
TopLink CMP Foundation Libraries are supersets of the TopLink Foundation
Library. You get all of the same functionality. However, these libraries
also allow you to use TopLink with CMP Entity Beans on BEA WebLogic
and IBM WebSphere application servers.
What
application servers does TopLink support?
TopLink can be used within any compliant J2EE and Web container
with various persistence architectures. However, TopLink does have
explicit support and certification testing performed with each release
on: Oracle Application Server, BEA WebLogic, and IBM WebSphere.
Other containers are supported through standard J2EE integration
and may require minor customizations.
TopLink provides a complete set of mappings for both direct and
reference relationships. This allows developers to map from the
object model to the relational model without one model dictating
to the other.
Direct Mappings
Direct To Field
Object Type
Type Conversion
Serialized Object
Direct To XML
Direct Collection
Direct Map
Transformation
Relationship Mappings
Aggregate Object
One To One
Variable One To One
One To Many
Many To Many
Direct Collection
Aggregate Collection
Object-relational Mappings
Structure
Reference
Nested Table
Array
Object Array
Can TopLink map
the private and protected fields?
TopLink can access non-public fields, methods, or both. Grant the
ReflectPermission permission to TopLink to suppress default Java
language access control checks when using reflected members and
constructors. The security policy file grants permissions using
the policy tool application.
Can you
map columns, which allow NULL, to primitive Java types?
Normally no, because primitive types in Java cannot be null. If
the field value is null and TopLink tries to assign null to a primitive,
Java raises a NullPointerException. The easiest way to avoid this
problem is to ensure that all the database fields that store primitive
values cannot be null. Using the TopLink Workbench, you
can also configure the mapping to use a default value for null by
using the NullValue property on all direct mappings. To do this
in code, you could use:
mapping.setNullValue(new Integer(0));
In addition, using Oracle TopLink Workbench, you can
configure NullValue for all mappings and descriptors on the DatabaseLogin.
To do this in code, you could use:
login.setDefaultNullValue(int.class, new Integer(0));
Does TopLink
support relationship mappings to interfaces as well as classes?
Yes, you can define mappings that reference interfaces instead
of classes. TopLink calls this a variable class mapping. Interfaces
can be defined for a single class or for a set of implementors.
Querying on the interface will query each of the implementors.
How do I define a
1:1 variable class mapping using TopLink?
TopLink supports variable 1:1 mappings in which the source object
has a reference to one of two or more non-inherited classes. To
define a variable 1:1 mapping, the target classes of the mapping
must be related through an interface.
You must define an interface descriptor for the interface, and
the target classes must implement the interface. The selection criteria
of the mapping will be defined using query keys from the target
interface, and a type field in the source object's table will store
the type of object that is referenced.
What does it
mean when a relationship mapping is privately owned?
TopLink provides the ability to define any reference mapping (1:1,
1:M, and M:M) as privately owned . This means that when the source
object is deleted so are all its privately owned parts.
Is it possible
to have multiple mappings to a single column?
Yes, provided that only one of the mappings is made writeable.
TopLink requires one writeable mapping for which it will retrieve
the required value from the object when constructing the row for
the database. You can configure a mapping to be read-only or, in
the case of a 1:1 mapping, may configure a target foreign key. Both
of these will allow an additional mapping of a field.
How do I generate and
assign primary keys to objects I create?
TopLink supports sequencing by assigning the object a unique identifier
when it is inserted into the database. TopLink assigns the identifier
here because this is the first time TopLink gets access to the object.
When using native sequencing on IBM Informix, Microsoft SQL Server,
and Sybase Adaptive Server, the identifier cannot be obtained until
after the insert.
Within a UnitOfWork, all registered new objects can also be assigned
sequence numbers through the assignSequenceNumber(Object) and assignSequenceNumbers()
methods.
How can I define
a selection criteria that is not only on foreign keys in a foreign
reference mapping?
Foreign reference mappings internally use a selection query to
read objects from the target. This selection query is like any other
read query, and can be accessed to provide advanced customization
on the mapping's query. The selection query can itself be changed
to provide a custom query if complex querying is required. If you
have a relationship that is not solely based on foreign keys, an
expression can be given to the mappings selection criteria.
ExpressionBuilder builder
= new ExpressionBuilder(); mapping.setSelectionCriteria( builder.getParameter("EMPLOYEE.ADDR_ID").equal(builder.getField("ADDRESS.ID").and(builder.getField(
"ADDRESS.TYPE").equal("home"));
When must I define a 1:1 mapping
back from the target to the source object in a 1:M mapping? Are there
alternatives?
When a source object defines a 1:M mapping to a target object,
you must also create a 1:1 mapping from the target object back to
the source object to populate the foreign key field in the target
table. Without this back-mapping, TopLink does not know how to populate
this foreign key field in the target table.
Use an AggregateCollectionMapping to represent the aggregate (privately-owned)
relationship between a single source object and a collection of
target objects. Unlike the normal 1:M mapping, there is no need
for setting the 1:1 back reference, because the foreign key relationships
have already been resolved by the aggregation.
You can avoid setting the 1:1 back reference by defining a direct-to-field
mapping on the foreign key field. In this case, the application
must make sure that the object model picks up the correct value
from the source object. However, this alternative may result in
an overly complex implementation or object model. We recommend you
use a 1:1 back reference.
Another alternative is to define a M:M mapping from source to target
and create a relation table. This is the best solution because it
ensures that the object model is consistent with the data model.
Neither model stores information about the relationship in the target
object, and multiple source objects referencing the target can be
supported.
How can I customize
the TopLink TypeConversionMapping to make use of a third-party class?
TopLink provides a rich set of type conversions between database
types and the Java types supplied with the JDK. It is possible to
make use of additional or third-party types in a domain class through
customization of TopLink.
TopLink makes use of a singleton ConversionManager (found in the
oracle.toplink.helper package). Developers can subclass this class
and create a custom conversion manager with the additional conversions
required. At system startup, an instance of this class must be provided
as the singleton conversion manager.
What types can I
use to hold the values for a collection mapping (1:M, M:M, and DirectCollection)?
By default, TopLink uses the Vector class for collections. TopLink
supports other collection types through the mapping's container
policy. You can define a new container policy that uses other types
of containers that do not implement the Collection or Map interfaces.
Can TopLink map BLOB data?
TopLink maps BLOB data from the database into a byte array in the
object model. BLOBs can also be mapped through transformation or
serialized mappings to be complex objects in the object model. Because
many JDBC drivers have problems dealing with large binary data,
TopLink supports multiple options. By default, TopLink binds binary
data into the SQL statement. TopLink also supports printing the
data using the JDBC binary escape clause or native SQL.
Binding is enabled or disabled on the DatabaseLogin through the
dont/useByteArrayBinding() property. When binding is enabled, TopLink
parameter binds the binary value. Because some JDBC drivers may
have problems binding large values (but can support large values
through streams), TopLink also supports stream binding. This is
enabled in DatabaseLogin through the useStreamBinding() property.
Some drivers have limits to BLOB sizes that may require your application
to split the binary data into multiple fields or use a direct collection
or 1:M mapping to map the data.
Large string data may also require binding. You can configure TopLink
to bind string data through the useStringBinding(int) property on
DatabaseLogin.
Serialized Mapping - TopLink also provides the ability to map
object structures, that would not map easily to relational tables,
with a SerializedObjectMapping. Mappings of this type serialize
the object structure from the root attribute and store it into
a BLOB field on the database. When the object is read from the
database, it is de-serialized into its original structure. This
mapping does not require the developer to perform the serialization,
but instead to make sure that objects in the structure are serializable
and self-contained.
TypeConversionMapping - The Oracle JDBC thin driver uses enhanced
methods to read and write LOB (BLOB and CLOB) information. TopLink
now supports reading and writing LOB information in this way.
To tell TopLink that the database type you are mapping to is a
LOB (BLOB or CLOB) type, map the attribute as a TypeConversionMapping.
TopLink will then call the appropriate methods.
What causes the
"invalid column name" message in SQL Exception?
This message is given because SQL is trying to write to a non-existent
column in the table. Possible reasons for this could be: The field
names specified in the foreign reference mapping are not properly
specified. The column name is misspelled or in the wrong case. Check
the methods where field names are set in the mapping.
I have set up sequencing,
but I am getting an error when inserting a new object. What is wrong?
It is likely that, although you set up the descriptor's and project's
sequencing information, the sequence table is not yet initialized.
The sequence table must contain one row for each sequence name you
are using, and have an initial value in the count column. For example,
if your Employee and Address descriptors are using sequencing, an
initialized sequence table might look like this:
SEQ_NAME
SEQ_COUNT
EMPLOYEE
0
ADDRESS
0
How do TopLink inheritance
mappings compare with Java class inheritance?
When TopLink maps a Java inheritance hierarchy, each class in the
hierarchy defines a TopLink descriptor. Each subclass' descriptor
defines its parent to be its superclass.
This inheritance hierarchy can be reflected in the database in
many ways. TopLink requires a common table for the root class that
must be shared by all the subclasses. The subclasses are free to
define additional tables to store their additional data or can share
their parent's tables. TopLink uses an indicator field in the root
table to determine the class to instantiate from the row; however,
this mechanism can be customized if required.
A common misconception is that a system with a root domain class
must be mapped using this kind of inheritance mapping. Typically,
this should be done only where the database schema dictates or the
object model allows similar types to be stored together. If it does
not make sense to define a table for the root class, this class
cannot be mapped at all, or can be mapped as an interface. TopLink
supports querying on interface descriptors and does not require
that they be mapped to a database table.
In a mapped inheritance hierarchy, all subclasses must share the
root's primary key. In case of multiple tables, the primary key
in the additional table can be named differently from the one located
in the root table. In this case, a name mapping must be provided
in the descriptor, or in complex cases a multiple table join expression.
The root table's primary key will always be used internally in TopLink
and for caching.
I
have a domain model with a lot of inheritance. Do I have to model
my inheritance in TopLink?
No. Inheritance in TopLink must be modeled relationally only if
you plan to query or write the super classes.
Consider an example where class A has a subclass B. A has two attributes:
id and description. On the database, there is both an ID and DESCRIPTION
field on B's table, but A has no table associated with it. With
TopLink, you simply map B; you can ignore its superclass A . The
fields contained in A can be mapped through mapping B.
This allows you to map an object model but ignore certain classes
that should not logically be persisted (such as abstract classes,
"PersistentObject" superclasses, etc.).
I have
specified Transparent Indirection for my mappings. Do I have to do
anything special to get it to work?
In general, no. You do, however, have to make sure that your attribute
is of the correct type. In the case of collection indirection, you
must make sure that your attribute type is java.util.Collection.
For one-to-one indirection, you must make sure that the attribute
type is an interface, since TopLink replaces the target object with
a special wrapper object that implements the same interfaces as
the target class. If the variable is not of the correct type, TopLink
will not be able to put the value into it.
Serialization can also cause trouble with Transparent Indirection.
Unless Remote Sessions are being used, Transparent Indirection cannot
be instantiated on the client. The same holds true with regular
indirection; however, the point at which the indirection is instantiated
is now different with Transparent Indirection. Using traditional
ValueHolders , the indirection is triggered as soon as the getAttribute()
method is called. Before an object that is referenced using Transparent
Indirection can be accessed on the client, a message must be sent
to it on the server (for example, getSize() for transparent collections,
hashCode() for transparent one-to-ones, and so on.).
Does TopLink provide
a way to plug in user defined object/data transformations?
Yes. A Transformation Mapping is used to define custom transformations.
How do I configure
TopLink to delete objects when an owner object is deleted (i.e., cascade
delete)?
Objects whose lifecycle is coupled to their owner are called "privately
owned" objects in TopLink. Privately owned objects are deleted
when their parent is deleted. The configuration of a relationship
as privately owned is specified on the descriptor either in the
MappingWorkbench, JDeveloper Mapping Editor, or directly in Java.
TopLink supports many different types of relationship mappings
(1:1, 1:Many, etc.) that you can used to define relationships. Refer
to Relational
Mapping Types, XML
Mapping Types, and EIS
Mapping Types in the Oracle TopLink Developer's Guide
for a complete list of available mappings.
Is it possible to map a
class to more than one table?
Yes. Attributes from a single class can be mapped to multiple tables.
Does TopLink support Oracle
Database’s XML data type?
Yes, using a direct-to-XMLType mapping you can map XML data in
the form of a String or an org.w3c.dom.Document object to an XMLType
column in an Oracle Database (introduced in version 9.2.0.1). TopLink
also provides expression operators to support querying XMLType.
You'll need to adjust the Workbench and runtime classpath to include
the Oracle Database xdb.jar.
In addition to EJB QL and SQL, TopLink's rich expression framework
allows almost any query to be specified in terms of the object model.
These expressions are then dynamically turned into the appropriate
SQL at runtime.
When you define a descriptor with the TopLink Workbench,
you can use the Queries tab to specify EJB QL and SQL queries and
finders to use for database access. The Queries tab contains two
additional tabs: Named Queries and Custom SQL.
For 2.0 CMP projects, the ejb-jar.xml file stores query lists.
You can define the queries in the file and then read them into the
TopLink Workbench, or define them on the Queries tab and
write them to the file.
Do TopLink queries support EJBQL?
A ReadAllQuery and ReadObjectQuery have the method setEJBQLString(String
EJBQLString), which you can use to set the selection criteria of
the query to a String containing EJB QL.
The TopLink Workbench also supports EJB QL queries.
What capabilities do
TopLink's expressions support?
TopLink's rich expression framework allows almost any query to
be specified in terms of the object model. These expressions are
then dynamically turned into the appropriate SQL at runtime. Features
of the expression framework include:
Operators, such as =, !=, <, <=, =, >, >=, in, like,
between
Logical operators, such as AND, OR, NOT
Traversing 1:1, 1:M, M:M relationships, joins (including outer
joins on most databases)
Object comparison
Common database functions and user defined functions
Can I have
both EJBQL queries and SQL queries in the same application?
Yes. Queries may be specified using any of the query types supported
by TopLink in any application. TopLink Expression, SQL, and EJBQL
queries can all be used in a single application if desired.
What if I don't like
the SQL TopLink generates for queries?
Queries can be specified directly in SQL if the SQL generated by
TopLink for Expression or EJBQL based queries is unacceptable. However,
this is not typically necessary.
The SQL generated by TopLink for reading, writing, and deleting
objects based on a class's descriptor can also be overridden.
Does TopLink support
table qualifiers and creators?
In some databases or database configurations, table names must
be qualified with either a table owner/creator name or a table space
name. TopLink allows you to specify these either on a per session
basis or individually in each descriptor.
By sending the following method to the DatabaseLogin object before
you login to the session, the table names of all of the registered
descriptors will be qualified with the creator or qualifier name.
login.setTableQualifier("PERSONNEL");
Individual qualifiers can be entered using the TopLink Workbench on a per-table basis.
How can I setup a Class
to query only the instances of the parent class but not the subclass
instances?
By default reading a parent class will return all the instances
of the parent and its subclasses. If only the instances of the parent
class are desired, then the inheritance property "should read subclasses"
can be turned off on the parent descriptor. If the subclass instances
are not desired for a specific query, then the query expression
can filter the children. The following gives an example of a subclass
filtering expression:
Expression builder = new ExpressionBuilder();
Expression expression = builder.getField("typeIndicatorField").equal("parent");
What
is the difference between a QueryByExample object and a selection
object?
A QueryByExample object does not replace a selection object in
a query. A QueryByExample object allows you to create an object
with various attributes set, to give you better control over your
query. A selection object is an easy mechanism to query by the primary
key only. Any other attributes in this object are ignored.
Can
you use more than one ExpressionBuilder subexpressions for a single
expression?
No, doing this might seem to be working in some cases but would
fail in expressions using joins or complex expressions. We recommend
that you always use the same ExpressionBuilder in a single expression.
If your expression contains subselects, then the subquery may have
a different ExpressionBuilder, but this should be the only case.
I keep getting
multiple joins when I use multiple anyOf( ) functions in my expression,
which is returning too many results. How do I get it down to one join
instead?
Each time you use anyOf() in your expression, you get another join
in your database. For example, the TopLink expression:
will return any Employee who manages a John or a Smith, not just
John Smith. This is because a separate join is performed for each
anyOf() . To force a single join, the same anyOf node must be used
for each query:
Some JDBC drivers do not support the JDBC date syntax. In this
case TopLink also supports printing date values in their native
database syntax. To enable native SQL printing set the useNativeSQL()
property in DatabaseLogin.
Why do I receive a conversion
exception when reading date values from my database?
TopLink optimizes how data is converted from the JDBC driver. This
includes date type where TopLink handles the conversion from strings
internally. Some JDBC drivers, when returning the string representation
of the date, return the wrong string syntax. In this case use the
dontOptimizeDataConversion() property in DatabaseLogin to disable
this optimization.
How do I query historical
data?
TopLink provides support for querying historical versions of an
object through an ObjectLevelReadQuery
with an AsOfClause,
in expressions using an asOf
operator, and through Historical Client Sessions. When using a non-Oracle
database platform you can query against a historical schema of your
own design that you configure with a TopLink HistoryPolicy. Oracle9i
Database Server (or later) automatically maintains historical versions
of objects and extends SQL with an AS_OF clause used to query this
historical data. Oracle refers to these as flashback queries. To
use TopLink's historical query support with Oracle9i database you
just have to configure your session with an OraclePlatform.
Yes, flashback queries can be performed using TopLink's historical
query support. Historical queries are described in the answer to
the question: How do I query historical data?
How do I ensure
that query results incorporate data inserted or updated in an as yet
uncommitted transaction?
Uuse conforming on a query. Calling the conformResultsInUnitOfWork()
method on a query before it is executed will ensure that uncommited
changes will be accounted for in the query result. This has the
downside of requiring extra processing of a query result and should
only be used when necessary.
Why is it faster to read objects
from the database the second time than it is the first time?
If caching is enabled for a particular class, then querying for
an instance of that class a second time will be faster than the
first time. This is due to TopLink finding the object in the cache
and thus saving the cost of constructing that object from database
data. Caching is specified at the class level and various cache
types can be selected.
TopLink uses an object's primary key field values, as defined in
the descriptor, to identify an object uniquely. The object cache,
maintained within either the DatabaseSession or ServerSession, caches
objects based on class and primary key values.
How does TopLink maintain
object identity?
Each class type has an identity map in a DatabaseSession or ServerSession.
Objects are stored in these identity maps based on the object's
defined primary key field values.
TopLink guarantees object identity by checking the cache during
reads to ensure that for any given set of relational data (that
maps to an object), only a single instance of the class is created,
so multiple reads of the same object return the same reference.
This feature is extremely valuable in ensuring that object changes
made within the application stay in sync with other users of the
objects. Object identity also allows the building of complex structures
involving circular references without any extra work or potential
infinite loop.
Violating object identity refers to creating objects that already
exist either in the cache (same class and primary key) or in the
database, instead of using the object returned from TopLink.
What caching options does TopLink
provide?
TopLink uses six types of caches that can be configured on a per
class basis.
None (NoIdentityMap )
Full (FullIdentityMap )
Cache (CacheIdentityMap, fixed size, drops least recently used
objects)
Weak (WeakIdentityMap )
Soft Cached Weak (SoftCacheWeakIdentityMap, default for Java
2)
Hard Cached Weak (HardCacheWeakIdentityMap )
Can TopLink create
classes from tables and automatically map them?
Yes. TopLink can generate EJB Entity Beans or Java classes from
tables and automatically map them to the source tables.
Refer to Generating
Descriptors and Classes from Database Tables in the Oracle
TopLink Developer's Guide for more information on using the
TopLink Workbench and the JDeveloper documentation for detailed
instruction on how to do this in JDeveloper.
Can TopLink create
tables from classes and automatically map them?
Yes. In the Mapping Workbench you can either generate tables for
all classes in you project or for select classes. Select the class
or classes you wish to generate tables for, right click, and choose
"Generate Tables from Descriptors". From there you can
either choose to generate tables for only the selected classes or
all classes in the project.
Can TopLink create
the database tables for me?
Yes. In the Mapping Workbench you can right click on any table
and choose "Create on Database" and then choose "All
Tables" or "Selected Tables". You must be logged
into the database for this menu option to be enabled. When using
TopLink in JDeveloper, you can create tables using the offline database
feature.
Stored procedures are accessed through TopLink's custom SQL and
stored procedure call support. To call stored procedures, you can
use the session API executeSQL(...) and executeNonSelectingSQL()
or in use a descriptor's or mapping's custom SQL properties. Stored
procedures with output parameters are supported through the StoredProcedureCall
object. You can also call Stored procedures with output parameters
inside the descriptor's and mapping's properties and execute them
directly on the session through the DataReadQuery and DataModifyQuery
objects.
What is the difference
between a DatabaseSession and a ServerSession?
TopLink provides two types of sessions for developers to connect
with the database:
DatabaseSession -- For two-tier applications in which a single
JDBC connection will service all database requests.
ServerSession -- For three-tier applications. This allows multiple
clients to access the database through a configurable JDBC connection
pool. TopLink's three-tier solution also includes a ClientSession
and a RemoteSession. Each client to the ServerSession must communicate
through a ClientSession. The RemoteSession can be used across
RMI, CORBA or EJB from a client applet or application.
DatabaseSession provides the UnitOfWork functionality and lower
level access to the database through insertObject(...), updateObject(...),
deleteObject(...), beginTransaction(), commitTransaction(), and
rollbackTransaction(). These are not provided through the ServerSession,
ClientSession, and RemoteSession because merging of objects into
a shared cache requires the more complicated behavior delivered
with TopLink's UnitOfWork .
Refer to Session
Types in the Oracle TopLink Developer's Guide for more
information.
What are a UnitOfWork and
a Client Session? What's the difference?
A client session gives the client access to the database (and
the session cache) through the server session. A client session
does not support database modification; it cannot create, change,
or delete objects directly. To perform database modification, a
client must obtain a Unit of Work from the client session. The Unit
of Work acts as an exclusive transactional object space, and also
ensures that any changes that are committed to the database also
occur in the session cache.
TopLink's UnitOfWork provides developers with an object transaction
mechanism. It provides a working copy of an object and its related
objects so that changes can be made in isolation. Upon commit, the
UnitOfWork identifies what has changed wit