Variable class one-to-many
Is it possible to have a variable class relationship for a one-to-many relationship?
John,
One option is to have a 1:M to an inheritance root. This will give you a collection of heterogeneous results with the ability to issue a single query on the root class.
Just be careful not to introduce extra inheritance just for flexibility as it can have negative performance impacts.
Doug
Similar Messages
-
How to pass a variable from one class to another class?
Hi,
Is it possible to pass a variable from one class to another? For e.g., I need the value of int a for calculation purpose in method doB() but I get an error <identifier> expected. What does the error mean? I know, it's a very, very simple question but once I learn this, I promise to remember it forever. Thank you.
class A {
int a;
int doA() {
a = a + 1;
return a;
class B {
int b;
A r = new A();
r.a; // error: <identifier> expected. What does that mean ?
int doB() {
int c = b/a; // error: operator / cannot be applied to a
}Thank you!elaine_g wrote:
I am wondering why does (r.a) give an error outside the method? What's the reason it only works when used inside the (b/r.a) maths function? This is illegal syntax:
class B {
int b;
A r = new A();
r.a; //syntax error
}Why? Class definition restricts what you can define within a class to a few things:
class X {
Y y = new Y(); //defining a field -- okay
public X() { //defining a constructor -- okay
void f() { //defining a method -- okay
}... and a few other things, but you can't just write "r.a" there. It also makes no sense -- that expression by itself just accesses a field and does nothing with it -- why bother?
This is also illegal syntax:
int doB() {
A r = new A();
r.a; // error: not a statement
}Again, all "r.a" does on its own is access a field and do nothing with it -- a "noop". Since it has no effect, writing this indicates confusion on the part of the coder, so it classified as a syntax error. There is no reason to write that. -
Moving Variable from one class to another.
I need to get a Variable from one class to another how would I do this?
Well this is a very tipical scehario for every enterprise application. You always create logger classes that generate log files for your application, as that is the only way to track errors in your system when its in the production enviorment.
Just create a simple class that acts as the Logger, and have a method in it that accepts a variable of the type that you are are trying to pass; most commonly a String; but can be overloaded to accept constom classes. e.g.
class Logger
public void log(String message)
writeToFile("< " + new Date() + " > " + message);
public void log(CustomClass queueEvent)
log("queue message was: " + queueEvent.getMessage() + " at: " + queueEven.getEventTime());
}Hope this makes things clearer
Regards
Omer -
Having trouble with the following poblem.. specially how to code getChildren??????? Help urgent
Create a class called Families which creates a one-to-many mapping of parent name (String) to Child objects. Create any needed member variables and write the two specified methods. (You do not need to write the Child class.)
class Families {
public void addToFamily( String parent, Child child) {
public List getChildren( String parent) {
I have done the following..
import java.util.ArrayList;
import java.util.List;
class Families {
private String parentName;
List <child> children = new ArrayList();
public Families(String name){
this.parentName = name;
public void addToFamily( String parent, child kid) {
Families f = new Families(parent);
f.children.add(kid);
public List<child> getChildren( String parent) {
return this.children;
}Having trouble with the following poblem.. specially
how to code getChildren??????? Help urgent
Create a class called Families which creates a
one-to-many mapping of parent name (String) to Child
objects. Create any needed member variables and write
the two specified methods. This key:
(You do not need to write the Child class.)How can the following line possibly work?
List <child> children = new ArrayList();It's not syntactically correct, AND you're not writing the Child class.
% -
One-to-many relation sometimes INSERTs child before parent
Hi,
I have a one-to-many relationship, say Company-Employee, that I want to be
managed by the parent entity (Company), so that when I make persistent the
Company, its Employees are also made persistent, and when I delete the
Company, its Employees are deleted. In my Java code, Company has an
ArrayList of Employees, and Employee has a Company member variable.
My metadata looks like this:
<class name="Company" identity-type="application">...
<field name="employees">
<collection element-type="Employee"/>
<extension vendor-name="kodo" key="inverse-owner" value="company"/>
<!-- delete all Employees when the Company is deleted -->
<extension vendor-name="kodo" key="element-dependent" value="true"/>
</field>
</class>
<class name="Employee" identity-type="application">...
<field name="company"/>
</class>
I have a test that is creating a Company with an Employee and persisting
it. It then deletes the Company. The test is passing some of the time and
failing some of the time. It seems to not be consistent with the ordering
of the INSERTs - sometimes it inserts Company then Employee, but sometimes
it first tries to insert into Employee, which fails with a foreign key
constraint to the parent table.
How can I force it to insert into the parent table first?
I notice that the documentation says you need the field of the child
entity to be the inverse-owner. Is it not possible for the parent entity
to own the relationship?
Many thanks,
AlexAlex,
If you have non-deferred foreign keys between the tables, and you turn
on Kodo's foreign key reordering algorithm, Kodo will ensure that all
your foreign key constraints are met, regardless of the ordering of the
operations in your Java code.
See http://docs.solarmetric.com/ref_guide_dbsetup_fks.html for details
about this.
Regarding inverse-owner specification -- is there any reason why you
want to specify this on the other side? inverse-owner basically defines
which side of a shared relationship defines the mappings and should be
monitored for changes; it does not have any impact on the mappings
themselves.
-Patrick
Alex Robbins wrote:
Hi,
I have a one-to-many relationship, say Company-Employee, that I want to be
managed by the parent entity (Company), so that when I make persistent the
Company, its Employees are also made persistent, and when I delete the
Company, its Employees are deleted. In my Java code, Company has an
ArrayList of Employees, and Employee has a Company member variable.
My metadata looks like this:
<class name="Company" identity-type="application">...
<field name="employees">
<collection element-type="Employee"/>
<extension vendor-name="kodo" key="inverse-owner" value="company"/>
<!-- delete all Employees when the Company is deleted -->
<extension vendor-name="kodo" key="element-dependent" value="true"/>
</field>
</class>
<class name="Employee" identity-type="application">...
<field name="company"/>
</class>
I have a test that is creating a Company with an Employee and persisting
it. It then deletes the Company. The test is passing some of the time and
failing some of the time. It seems to not be consistent with the ordering
of the INSERTs - sometimes it inserts Company then Employee, but sometimes
it first tries to insert into Employee, which fails with a foreign key
constraint to the parent table.
How can I force it to insert into the parent table first?
I notice that the documentation says you need the field of the child
entity to be the inverse-owner. Is it not possible for the parent entity
to own the relationship?
Many thanks,
Alex -
Java.io.NotSerializableException - while retriving "one to many" objects
i am getting java.rmi.MarshalException java.io.NotSerializableException
while i try to retrive one to many objects
i have recently migrated from kodo 2.5.x to kodo 3.0.1, and i have parent
object reference in child objects (reverse mapping reference according to
kodo 2.5.x) as shown below
public class BankStatementEntry implements BankStatement {
private Set accountSummary = new HashSet();
public interface BankStatement extends Serializable {
* Returns the accountSummary.
* @return Map
public Set getAccountSummary();
* Returns the accountSummary.
* @return Map
public void setAccountSummary(Set accountSummary);
public class AccountSummaryRecord implements AccountSummary {
private BankStatementEntry bankStatementEntry;
public interface AccountSummary extends Serializable {
* Returns the transactionDetails.
* @return Collection
public Set getTransactionDetails();
the problem is, when i try to retrive BankStatementEntry object, i have to
iterate through each child (AccountSummaryRecord) object and manualy
remove parent object reference (BankStatementEntry) by setting null.
Otherwise EJB throws java.io.NotSerializableException
Is this bug ?
Thanks
karup.Thread [Servlet.Engine.Transports : 1] (Suspended)
java.io.NotSerializableException.<init>() line: 50 [local variables
unavailable]
com.ibm.CORBA.iiop.UtilDelegateImpl.copyObjectByProxy(java.lang.Object,
org.omg.CORBA.ORB, java.lang.ClassLoader, java.lang.Class,
org.omg.CORBA.portable.Streamable) line: 1316 [local variables unavailable]
com.ibm.ws.orb.WSUtilDelegateImpl(com.ibm.CORBA.iiop.UtilDelegateImpl).copyObject(java.lang.Object,
org.omg.CORBA.ORB) line: 771 [local variables unavailable]
javax.rmi.CORBA.Util.copyObject(java.lang.Object, org.omg.CORBA.ORB)
line: 327 [local variables unavailable]
au.com.aig.aiaa.paymentdishonor.process.ejb._BankStatementProcessor_Stub.fetchBankStatement(java.util.Date,
java.util.Date) line: 366
au.com.aig.aiaa.business.process.ejb.CommonFacadeBean.fetchBankStatement(java.util.Date,
java.util.Date) line: 102
au.com.aig.aiaa.business.process.ejb.EJSRemoteStatelessCommonFacade_aa40cc36.fetchBankStatement(java.util.Date,
java.util.Date) line: 61
au.com.aig.aiaa.business.process.ejb._CommonFacade_Stub.fetchBankStatement(java.util.Date,
java.util.Date) line: 266
au.com.aig.aiaa.paymentdishonor.web.ReportsAction.execute(org.apache.struts.action.ActionMapping,
org.apache.struts.action.ActionForm,
javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse) line: 67
org.apache.struts.action.RequestProcessor.processActionPerform(javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse, org.apache.struts.action.Action,
org.apache.struts.action.ActionForm,
org.apache.struts.action.ActionMapping) line: 446
org.apache.struts.action.RequestProcessor.process(javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse) line: 266
org.apache.struts.action.ActionServlet.process(javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse) line: 1292
org.apache.struts.action.ActionServlet.doGet(javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse) line: 492
org.apache.struts.action.ActionServlet(javax.servlet.http.HttpServlet).service(javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse) line: 740
org.apache.struts.action.ActionServlet(javax.servlet.http.HttpServlet).service(javax.servlet.ServletRequest,
javax.servlet.ServletResponse) line: 853
com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(javax.servlet.ServletRequest,
javax.servlet.ServletResponse) line: 110 [local variables unavailable]
com.ibm.ws.webcontainer.servlet.StrictServletInstance(com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet)._service(javax.servlet.ServletRequest,
javax.servlet.ServletResponse) line: 174 [local variables unavailable]
com.ibm.ws.webcontainer.servlet.IdleServletState.service(com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet,
javax.servlet.ServletRequest, javax.servlet.ServletResponse) line: 313
[local variables unavailable]
com.ibm.ws.webcontainer.servlet.StrictServletInstance(com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet).service(javax.servlet.ServletRequest,
javax.servlet.ServletResponse) line: 116 [local variables unavailable]
com.ibm.ws.webcontainer.servlet.ServletInstance.service(javax.servlet.ServletRequest,
javax.servlet.ServletResponse,
com.ibm.ws.webcontainer.webapp.WebAppServletInvocationEvent) line: 258
[local variables unavailable]
com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(com.ibm.ws.webcontainer.servlet.ServletInstanceReference,
javax.servlet.ServletRequest, javax.servlet.ServletResponse,
com.ibm.ws.webcontainer.webapp.WebAppServletInvocationEvent) line: 42
[local variables unavailable]
com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(javax.servlet.ServletRequest,
javax.servlet.ServletResponse,
com.ibm.ws.webcontainer.webapp.WebAppServletInvocationEvent) line: 40
[local variables unavailable]
com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(com.ibm.ws.webcontainer.webapp.WebAppRequest,
javax.servlet.http.HttpServletResponse) line: 872 [local variables
unavailable]
com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(javax.servlet.ServletRequest,
javax.servlet.ServletResponse, boolean) line: 491 [local variables
unavailable]
com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(javax.servlet.ServletRequest,
javax.servlet.ServletResponse) line: 173 [local variables unavailable]
com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse) line: 79 [local variables
unavailable]
com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(java.lang.Object)
line: 199 [local variables unavailable]
com.ibm.ws.webcontainer.srt.WebAppInvoker(com.ibm.ws.webcontainer.cache.invocation.CachedInvocation).handleInvocation(java.lang.Object)
line: 71 [local variables unavailable]
com.ibm.ws.webcontainer.cache.invocation.CacheableInvocationContext.invoke(java.lang.Object)
line: 114 [local variables unavailable]
com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(java.lang.String,
com.ibm.ws.webcontainer.srp.ISRPConnection) line: 187 [local variables
unavailable]
com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(com.ibm.ws.webcontainer.oselistener.api.IOSEConnection)
line: 331 [local variables unavailable]
com.ibm.ws.webcontainer.http.HttpConnection.handleRequest() line: 56
[local variables unavailable]
com.ibm.ws.webcontainer.http.HttpConnection(com.ibm.ws.http.HttpConnection).readAndHandleRequest()
line: 432 [local variables unavailable]
com.ibm.ws.webcontainer.http.HttpConnection(com.ibm.ws.http.HttpConnection).run()
line: 343 [local variables unavailable]
com.ibm.ws.util.ThreadPool$Worker.run() line: 592 [local variables
unavailable] -
Dount in Hibernate - One-to-many relationship
Hi ,
I have a doubt in hibernate mappings for one-to-many.
these are the two bean classes:
public class Register {
protected String userid;
protected String firstname;
protected String lastname;
protected String password;
protected String email;
protected String language;
protected Address address;
protected Set contacts;
protected Set events;
public class Event {
protected Long eventid;
protected String eventname;
protected Date eventdate;
protected Set confirmations;
protected Invitation invitation;
and here is the hibernate mapping for the register class :
<set name="events" table="EVENT" lazy="true" inverse="true" cascade="all" sort="unsorted" optimistic-lock="true" embed-xml="true">
<key column="USER_ID" on-delete="noaction"/>
<one-to-many class="com.evite.beans.Event" not-found="exception" embed-xml="true"/>
</set> the table decription is :
Register table :
USER_ID - PK
ADDRESS_ID
FIRSTNAME
LASTNAME
PASSWORD
EMAIL
LANGUAGE
Event Table:
EVENT_ID | PK
INVITATION_ID |
EVENTNAME |
EVENTDATE |
USER_ID | FK
Now while inserting records the register object is created first in the program and inserted into the tables .at a later stage when the user(corresponding to register table record) adds events how do i insert the user_id also in the table ?
The event tables does not have variable for user id......
If i have to add the user_id variable in the bean class how do i map it to the table ?
Someone pls reply !!!!
Thanks in advance!
susenYou need to declare a link table between the two. Change your attribute entry to read thus:
<set name="events" table="register_event_link" ...Then re-export your schema. This will create the link table. When you add Event and do a saveOrUpdate() on the register instance, any unsaved Event objects will be saved to the events table and appropriate rows will be added to the register_event_link table to preserve the state of the set.
I would recommend purchasing a copy of Hibernate In Action if you do not already have one.
Dave. -
Data services and one to many foreign keys?
Hi,
I am playing with the data features in Flash4. I can get a flex app to work that will query and update a J2EE entity that has no foreign keys, but when I try the same with an entity that has many to one foreign keys I get a null pointer error coming from the server. I created a servlet to do the same update and that worked.
I'm wondering if the issue is a casting issue. I know I have to do the configure data types thing to some of the generated service calls to let it know what action script class is appropriate (instead of a generic object ) e.g. findAll(). Do I have to do a similar thing for one to many foreign key situations? i.e. lets say i have a department - employees model. On the java side the department entity has a variable that is a set of employees. In the department.as class I'd have a employees field thats an ArrayCollection. Do I have to let it know somewhere that this is an ArrayCollection of employee.as objects?
FYI, I've already changed to eager fetching of the fk values.
Does anyone have this working?
Thanks,
BillHi,
Thanks for your feedback!
This looks like an issue.
Can you please log a bug in http://bugs.adobe.com/flex with your sample.
Thanks,
Balaji
http://balajisridhar.wordpress.com -
Unable to read one-to-many relations using Hibernate
Hi,
I am trying with a very simple one-to-many relationship. When I am storing the objects, there are no problems. But when I am trying to read out the collection, it says invalid descriptor index. Please help.
Regards,
Hibernate version:
hibernate-3.1rc2
Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="Parent">
<id name="id">
<generator class="identity"/>
</id>
<set name="children">
<key column="parent_id"/>
<one-to-many class="Child"/>
</set>
</class>
<class name="Child">
<id name="id">
<generator class="identity"/>
</id>
<property name="name"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
The Parent class:
public class Parent
private Long id ;
private Set children;
Parent(){}
public Long getId()
return id;
public void setId(Long id)
this.id=id;
public Set getChildren()
return children;
public void setChildren(Set children)
this.children=children;
The Child class:
public class Child
private Long id;
private String name;
Child(){}
public Long getId()
return id;
private void setId(Long id)
this.id=id;
public String getName()
return name;
public void setName(String name)
this.name=name;
The Main class:
public class PCManager
public static void main(String[] args)
PCManager mgr = new PCManager();
List lt = null;
if (args[0].equals("store"))
mgr.createAndStoreParent(new HashSet(3));
else if (args[0].equals("list"))
mgr.listEvents();
HibernateUtil.getSessionFactory().close();
private void createAndStoreParent(HashSet s)
HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction();
Parent p1 = new Parent();
int size = 3;
for (int i=size; i>0; i--)
Child c = new Child();
c.setName("Child"+i);
s.add(c);
p1.setChildren (s);
Iterator elems = s.iterator();
do {
Child ch = (Child) elems.next();
HibernateUtil.getSessionFactory().getCurrentSession().save(ch);
}while(elems.hasNext());
HibernateUtil.getSessionFactory().getCurrentSession().save(p1);
HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().commit();
private void listEvents()
HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction();
Parent result = (Parent) HibernateUtil.getSessionFactory().getCurrentSession().load(Parent.class, new Long(1));
System.out.println("Id is :"+ result.getId());
Set children = result.getChildren();
Iterator elems = children.iterator();
do {
Child ch = (Child) elems.next();
System.out.println("Child Name"+ ch.getName());
}while(elems.hasNext());
HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().commit();
Full stack trace of any exception that occurs:
When I run with "hbm2ddl.auto" property as validate and trying to list the contents, I get the following out put.
C:\Documents and Settings\mirza\Desktop\hibernate-3.1rc2\MyHibernate>ant run -Da
ction=list
Buildfile: build.xml
clean:
[delete] Deleting directory C:\Documents and Settings\mirza\Desktop\hibernate
-3.1rc2\MyHibernate\bin
[mkdir] Created dir: C:\Documents and Settings\mirza\Desktop\hibernate-3.1rc
2\MyHibernate\bin
copy-resources:
[copy] Copying 4 files to C:\Documents and Settings\mirza\Desktop\hibernate
-3.1rc2\MyHibernate\bin
compile:
[javac] Compiling 5 source files to C:\Documents and Settings\mirza\Desktop\
hibernate-3.1rc2\MyHibernate\bin
run:
[java] 09:09:23,433 INFO Environment:474 - Hibernate 3.1 rc2
[java] 09:09:23,449 INFO Environment:489 - loaded properties from resource
hibernate.properties: {hibernate.cglib.use_reflection_optimizer=true, hibernate
.cache.provider_class=org.hibernate.cache.HashtableCacheProvider, hibernate.dial
ect=org.hibernate.dialect.SQLServerDialect, hibernate.max_fetch_depth=1, hiberna
te.jdbc.use_streams_for_binary=true, hibernate.format_sql=true, hibernate.query.
substitutions=yes 'Y', no 'N', hibernate.proxool.pool_alias=pool1, hibernate.cac
he.region_prefix=hibernate.test, hibernate.jdbc.batch_versioned_data=true, hiber
nate.connection.pool_size=1}
[java] 09:09:23,465 INFO Environment:519 - using java.io streams to persis
t binary types
[java] 09:09:23,465 INFO Environment:520 - using CGLIB reflection optimize
r
[java] 09:09:23,481 INFO Environment:550 - using JDK 1.4 java.sql.Timestam
p handling
[java] 09:09:23,559 INFO Configuration:1257 - configuring from resource: /
hibernate.cfg.xml
[java] 09:09:23,559 INFO Configuration:1234 - Configuration resource: /hib
ernate.cfg.xml
[java] 09:09:23,872 INFO Configuration:460 - Reading mappings from resourc
e: PCMapping.hbm.xml
[java] 09:09:24,013 INFO HbmBinder:266 - Mapping class: Parent -> Parent
[java] 09:09:24,045 INFO HbmBinder:266 - Mapping class: Child -> Child
[java] 09:09:24,045 INFO Configuration:1368 - Configured SessionFactory: n
ull
[java] 09:09:24,061 INFO Configuration:1014 - processing extends queue
[java] 09:09:24,061 INFO Configuration:1018 - processing collection mappin
gs
[java] 09:09:24,061 INFO HbmBinder:2233 - Mapping collection: Parent.child
ren -> Child
[java] 09:09:24,076 INFO Configuration:1027 - processing association prope
rty references
[java] 09:09:24,076 INFO Configuration:1049 - processing foreign key const
raints
[java] 09:09:24,155 INFO DriverManagerConnectionProvider:41 - Using Hibern
ate built-in connection pool (not for production use!)
[java] 09:09:24,170 INFO DriverManagerConnectionProvider:42 - Hibernate co
nnection pool size: 1
[java] 09:09:24,170 INFO DriverManagerConnectionProvider:45 - autocommit m
ode: false
[java] 09:09:24,170 INFO DriverManagerConnectionProvider:80 - using driver
: sun.jdbc.odbc.JdbcOdbcDriver at URL: jdbc:odbc:MySQL
[java] 09:09:24,170 INFO DriverManagerConnectionProvider:86 - connection p
roperties: {}
[java] 09:09:24,264 INFO SettingsFactory:77 - RDBMS: Microsoft SQL Server,
version: 08.00.0194
[java] 09:09:24,264 INFO SettingsFactory:78 - JDBC driver: JDBC-ODBC Bridg
e (SQLSRV32.DLL), version: 2.0001 (03.85.1117)
[java] 09:09:24,296 INFO Dialect:100 - Using dialect: org.hibernate.dialec
t.SQLServerDialect
[java] 09:09:24,311 INFO TransactionFactoryFactory:31 - Using default tran
saction strategy (direct JDBC transactions)
[java] 09:09:24,327 INFO TransactionManagerLookupFactory:33 - No Transacti
onManagerLookup configured (in JTA environment, use of read-write or transaction
al second-level cache is not recommended)
[java] 09:09:24,327 INFO SettingsFactory:125 - Automatic flush during befo
reCompletion(): disabled
[java] 09:09:24,327 INFO SettingsFactory:129 - Automatic session close at
end of transaction: disabled
[java] 09:09:24,343 INFO SettingsFactory:144 - Scrollable result sets: ena
bled
[java] 09:09:24,343 INFO SettingsFactory:152 - JDBC3 getGeneratedKeys(): d
isabled
[java] 09:09:24,343 INFO SettingsFactory:160 - Connection release mode: au
to
[java] 09:09:24,358 INFO SettingsFactory:184 - Maximum outer join fetch de
pth: 1
[java] 09:09:24,358 INFO SettingsFactory:187 - Default batch fetch size: 1
[java] 09:09:24,358 INFO SettingsFactory:191 - Generate SQL with comments:
disabled
[java] 09:09:24,358 INFO SettingsFactory:195 - Order SQL updates by primar
y key: disabled
[java] 09:09:24,358 INFO SettingsFactory:338 - Query translator: org.hiber
nate.hql.ast.ASTQueryTranslatorFactory
[java] 09:09:24,374 INFO ASTQueryTranslatorFactory:21 - Using ASTQueryTran
slatorFactory
[java] 09:09:24,374 INFO SettingsFactory:203 - Query language substitution
s: {no='N', yes='Y'}
[java] 09:09:24,374 INFO SettingsFactory:209 - Second-level cache: enabled
[java] 09:09:24,374 INFO SettingsFactory:213 - Query cache: disabled
[java] 09:09:24,374 INFO SettingsFactory:325 - Cache provider: org.hiberna
te.cache.HashtableCacheProvider
[java] 09:09:24,374 INFO SettingsFactory:228 - Optimize cache for minimal
puts: disabled
[java] 09:09:24,374 INFO SettingsFactory:233 - Cache region prefix: hibern
ate.test
[java] 09:09:24,405 INFO SettingsFactory:237 - Structured second-level cac
he entries: disabled
[java] 09:09:24,437 INFO SettingsFactory:257 - Echoing all SQL to stdout
[java] 09:09:24,452 INFO SettingsFactory:264 - Statistics: disabled
[java] 09:09:24,452 INFO SettingsFactory:268 - Deleted entity synthetic id
entifier rollback: disabled
[java] 09:09:24,452 INFO SettingsFactory:283 - Default entity-mode: POJO
[java] 09:09:24,593 INFO SessionFactoryImpl:155 - building session factory
[java] 09:09:24,938 INFO SessionFactoryObjectFactory:82 - Not binding fact
ory to JNDI, no JNDI name configured
[java] 09:09:24,954 INFO SchemaValidator:99 - Running schema validator
[java] 09:09:24,954 INFO SchemaValidator:107 - fetching database metadata
[java] 09:09:24,954 INFO Configuration:1014 - processing extends queue
[java] 09:09:24,954 INFO Configuration:1018 - processing collection mappin
gs
[java] 09:09:24,954 INFO Configuration:1027 - processing association prope
rty references
[java] 09:09:24,954 INFO Configuration:1049 - processing foreign key const
raints
[java] 09:09:24,985 WARN JDBCExceptionReporter:71 - SQL Error: 0, SQLState
: S1002
[java] 09:09:24,985 ERROR JDBCExceptionReporter:72 - [Microsoft][ODBC SQL S
erver Driver]Invalid Descriptor Index
[java] 09:09:25,001 ERROR SchemaValidator:129 - Error closing connection
[java] java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]Invalid transaction state
[java] Initial SessionFactory creation failed.org.hibernate.exception.Gener
icJDBCException: could not get table metadata: Child
[java] java.lang.ExceptionInInitializerError
[java] at HibernateUtil.<clinit>(Unknown Source)
[java] at PCManager.listEvents(Unknown Source)
[java] at PCManager.main(Unknown Source)
[java] Caused by: org.hibernate.exception.GenericJDBCException: could not g
et table metadata: Child
[java] at org.hibernate.exception.SQLStateConverter.handledNonSpecificE
xception(SQLStateConverter.java:91)
[java] at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6879)
[java] at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7036)
[java] at sun.jdbc.odbc.JdbcOdbc.SQLDisconnect(JdbcOdbc.java:2988)
[java] at sun.jdbc.odbc.JdbcOdbcDriver.disconnect(JdbcOdbcDriver.java:9
80)
[java] at sun.jdbc.odbc.JdbcOdbcConnection.close(JdbcOdbcConnection.jav
a:739)
[java] at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaVal
idator.java:125)
[java] at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryIm
pl.java:299)
[java] at org.hibernate.cfg.Configuration.buildSessionFactory(Configura
tion.java:1145)
[java] at HibernateUtil.<clinit>(Unknown Source)
[java] at org.hibernate.exception.SQLStateConverter.convert(SQLStateCon
verter.java:79)
[java] at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExcep
tionHelper.java:43)
[java] at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExcep
tionHelper.java:29)
[java] at org.hibernate.tool.hbm2ddl.DatabaseMetadata.getTableMetadata(
DatabaseMetadata.java:100)
[java] at org.hibernate.cfg.Configuration.validateSchema(Configuration.
java:946)
[java] at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaVal
idator.java:116)
[java] at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryIm
pl.java:299)
[java] at org.hibernate.cfg.Configuration.buildSessionFactory(Configura
tion.java:1145)
[java] ... 3 more
[java] Caused by: java.sql.SQLException: [Microsoft][ODBC SQL Server Driver
]Invalid Descriptor Index
[java] at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6879)
[java] at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7036)
[java] at sun.jdbc.odbc.JdbcOdbc.SQLGetDataString(JdbcOdbc.java:3862)
[java] at sun.jdbc.odbc.JdbcOdbcResultSet.getDataString(JdbcOdbcResultS
et.java:5561)
[java] at sun.jdbc.odbc.JdbcOdbcResultSet.getString(JdbcOdbcResultSet.j
ava:338)
[java] at sun.jdbc.odbc.JdbcOdbcResultSet.getString(JdbcOdbcResultSet.j
ava:395)
[java] at PCManager.listEvents(Unknown Source)
[java] at PCManager.main(Unknown Source)
[java] at org.hibernate.tool.hbm2ddl.TableMetadata.<init>(TableMetadata
.java:30)
[java] at org.hibernate.tool.hbm2ddl.DatabaseMetadata.getTableMetadata(
DatabaseMetadata.java:85)
[java] ... 7 more
[java] Exception in thread "main"
[java] Java Result: 1
BUILD SUCCESSFUL
Total time: 4 seconds
Name and version of the database you are using:
Microsoft SQLServer2000
The generated SQL (show_sql=true):
When the program is run with "hbm2ddl.auto" property as create, I get the following output.
C:\Documents and Settings\mirza\Desktop\hibernate-3.1rc2\MyHibernate>ant run -Daction=store
Buildfile: build.xml
clean:
[delete] Deleting directory C:\Documents and Settings\mirza\Desktop\hibernate
-3.1rc2\MyHibernate\bin
[mkdir] Created dir: C:\Documents and Settings\mirza\Desktop\hibernate-3.1rc
2\MyHibernate\bin
copy-resources:
[copy] Copying 4 files to C:\Documents and Settings\mirza\Desktop\hibernate
-3.1rc2\MyHibernate\bin
compile:
[javac] Compiling 5 source files to C:\Documents and Settings\mirza\Desktop\
hibernate-3.1rc2\MyHibernate\bin
run:
[java] 09:12:54,820 INFO Environment:474 - Hibernate 3.1 rc2
[java] 09:12:54,836 INFO Environment:489 - loaded properties from resource
hibernate.properties: {hibernate.cglib.use_reflection_optimizer=true, hibernate
.cache.provider_class=org.hibernate.cache.HashtableCacheProvider, hibernate.dial
ect=org.hibernate.dialect.SQLServerDialect, hibernate.max_fetch_depth=1, hiberna
te.jdbc.use_streams_for_binary=true, hibernate.format_sql=true, hibernate.query.
substitutions=yes 'Y', no 'N', hibernate.proxool.pool_alias=pool1, hibernate.cac
he.region_prefix=hibernate.test, hibernate.jdbc.batch_versioned_data=true, hiber
nate.connection.pool_size=1}
[java] 09:12:54,852 INFO Environment:519 - using java.io streams to persis
t binary types
[java] 09:12:54,852 INFO Environment:520 - using CGLIB reflection optimize
r
[java] 09:12:54,867 INFO Environment:550 - using JDK 1.4 java.sql.Timestam
p handling
[java] 09:12:54,946 INFO Configuration:1257 - configuring from resource: /
hibernate.cfg.xml
[java] 09:12:54,946 INFO Configuration:1234 - Configuration resource: /hib
ernate.cfg.xml
[java] 09:12:55,259 INFO Configuration:460 - Reading mappings from resourc
e: PCMapping.hbm.xml
[java] 09:12:55,400 INFO HbmBinder:266 - Mapping class: Parent -> Parent
[java] 09:12:55,447 INFO HbmBinder:266 - Mapping class: Child -> Child
[java] 09:12:55,447 INFO Configuration:1368 - Configured SessionFactory: n
ull
[java] 09:12:55,447 INFO Configuration:1014 - processing extends queue
[java] 09:12:55,447 INFO Configuration:1018 - processing collection mappin
gs
[java] 09:12:55,447 INFO HbmBinder:2233 - Mapping collection: Parent.child
ren -> Child
[java] 09:12:55,463 INFO Configuration:1027 - processing association prope
rty references
[java] 09:12:55,479 INFO Configuration:1049 - processing foreign key const
raints
[java] 09:12:55,557 INFO DriverManagerConnectionProvider:41 - Using Hibern
ate built-in connection pool (not for production use!)
[java] 09:12:55,557 INFO DriverManagerConnectionProvider:42 - Hibernate co
nnection pool size: 1
[java] 09:12:55,557 INFO DriverManagerConnectionProvider:45 - autocommit m
ode: false
[java] 09:12:55,573 INFO DriverManagerConnectionProvider:80 - using driver
: sun.jdbc.odbc.JdbcOdbcDriver at URL: jdbc:odbc:MySQL
[java] 09:12:55,573 INFO DriverManagerConnectionProvider:86 - connection p
roperties: {}
[java] 09:12:55,651 INFO SettingsFactory:77 - RDBMS: Microsoft SQL Server,
version: 08.00.0194
[java] 09:12:55,667 INFO SettingsFactory:78 - JDBC driver: JDBC-ODBC Bridg
e (SQLSRV32.DLL), version: 2.0001 (03.85.1117)
[java] 09:12:55,682 INFO Dialect:100 - Using dialect: org.hibernate.dialec
t.SQLServerDialect
[java] 09:12:55,698 INFO TransactionFactoryFactory:31 - Using default tran
saction strategy (direct JDBC transactions)
[java] 09:12:55,714 INFO TransactionManagerLookupFactory:33 - No Transacti
onManagerLookup configured (in JTA environment, use of read-write or transaction
al second-level cache is not recommended)
[java] 09:12:55,714 INFO SettingsFactory:125 - Automatic flush during befo
reCompletion(): disabled
[java] 09:12:55,714 INFO SettingsFactory:129 - Automatic session close at
end of transaction: disabled
[java] 09:12:55,729 INFO SettingsFactory:144 - Scrollable result sets: ena
bled
[java] 09:12:55,729 INFO SettingsFactory:152 - JDBC3 getGeneratedKeys(): d
isabled
[java] 09:12:55,745 INFO SettingsFactory:160 - Connection release mode: au
to
[java] 09:12:55,745 INFO SettingsFactory:184 - Maximum outer join fetch de
pth: 1
[java] 09:12:55,745 INFO SettingsFactory:187 - Default batch fetch size: 1
[java] 09:12:55,745 INFO SettingsFactory:191 - Generate SQL with comments:
disabled
[java] 09:12:55,745 INFO SettingsFactory:195 - Order SQL updates by primar
y key: disabled
[java] 09:12:55,745 INFO SettingsFactory:338 - Query translator: org.hiber
nate.hql.ast.ASTQueryTranslatorFactory
[java] 09:12:55,777 INFO ASTQueryTranslatorFactory:21 - Using ASTQueryTran
slatorFactory
[java] 09:12:55,792 INFO SettingsFactory:203 - Query language substitution
s: {no='N', yes='Y'}
[java] 09:12:55,792 INFO SettingsFactory:209 - Second-level cache: enabled
[java] 09:12:55,792 INFO SettingsFactory:213 - Query cache: disabled
[java] 09:12:55,792 INFO SettingsFactory:325 - Cache provider: org.hiberna
te.cache.HashtableCacheProvider
[java] 09:12:55,808 INFO SettingsFactory:228 - Optimize cache for minimal
puts: disabled
[java] 09:12:55,808 INFO SettingsFactory:233 - Cache region prefix: hibern
ate.test
[java] 09:12:55,808 INFO SettingsFactory:237 - Structured second-level cac
he entries: disabled
[java] 09:12:55,839 INFO SettingsFactory:257 - Echoing all SQL to stdout
[java] 09:12:55,839 INFO SettingsFactory:264 - Statistics: disabled
[java] 09:12:55,839 INFO SettingsFactory:268 - Deleted entity synthetic id
entifier rollback: disabled
[java] 09:12:55,839 INFO SettingsFactory:283 - Default entity-mode: POJO
[java] 09:12:55,980 INFO SessionFactoryImpl:155 - building session factory
[java] 09:12:56,325 INFO SessionFactoryObjectFactory:82 - Not binding fact
ory to JNDI, no JNDI name configured
[java] 09:12:56,341 INFO Configuration:1014 - processing extends queue
[java] 09:12:56,341 INFO Configuration:1018 - processing collection mappin
gs
[java] 09:12:56,341 INFO Configuration:1027 - processing association prope
rty references
[java] 09:12:56,341 INFO Configuration:1049 - processing foreign key const
raints
[java] 09:12:56,356 INFO Configuration:1014 - processing extends queue
[java] 09:12:56,356 INFO Configuration:1018 - processing collection mappin
gs
[java] 09:12:56,356 INFO Configuration:1027 - processing association prope
rty references
[java] 09:12:56,372 INFO Configuration:1049 - processing foreign key const
raints
[java] 09:12:56,372 INFO SchemaExport:153 - Running hbm2ddl schema export
[java] 09:12:56,388 DEBUG SchemaExport:171 - import file not found: /import
.sql
[java] 09:12:56,388 INFO SchemaExport:180 - exporting generated schema to
database
[java] 09:12:56,403 DEBUG SchemaExport:283 -
[java] alter table Child
[java] drop constraint FK3E104FC976A59A
[java] 09:12:56,466 DEBUG SchemaExport:283 -
[java] drop table Child
[java] 09:12:56,544 DEBUG SchemaExport:283 -
[java] drop table Parent
[java] 09:12:56,654 DEBUG SchemaExport:283 -
[java] create table Child (
[java] id numeric(19,0) identity not null,
[java] name varchar(255) null,
[java] parent_id numeric(19,0) null,
[java] primary key (id)
[java] )
[java] 09:12:56,779 DEBUG SchemaExport:283 -
[java] create table Parent (
[java] id numeric(19,0) identity not null,
[java] primary key (id)
[java] )
[java] 09:12:56,873 DEBUG SchemaExport:283 -
[java] alter table Child
[java] add constraint FK3E104FC976A59A
[java] foreign key (parent_id)
[java] references Parent
[java] 09:12:56,952 INFO SchemaExport:200 - schema export complete
[java] 09:12:56,952 WARN JDBCExceptionReporter:48 - SQL Warning: 5701, SQL
State: 01000
[java] 09:12:56,952 WARN JDBCExceptionReporter:49 - [Microsoft][ODBC SQL S
erver Driver][SQL Server]Changed database context to 'master'.
[java] 09:12:56,952 WARN JDBCExceptionReporter:48 - SQL Warning: 5703, SQL
State: 01000
[java] 09:12:56,952 WARN JDBCExceptionReporter:49 - [Microsoft][ODBC SQL S
erver Driver][SQL Server]Changed language setting to us_english.
[java] 09:12:56,983 INFO SessionFactoryImpl:432 - Checking 0 named queries
[java] Hibernate:
[java] insert
[java] into
[java] Child
[java] (name)
[java] values
[java] (?) select
[java] scope_identity()
[java] Hibernate:
[java] insert
[java] into
[java] Child
[java] (name)
[java] values
[java] (?) select
[java] scope_identity()
[java] Hibernate:
[java] insert
[java] into
[java] Child
[java] (name)
[java] values
[java] (?) select
[java] scope_identity()
[java] Hibernate:
[java] insert
[java] into
[java] Parent
[java] default
[java] values
[java] select
[java] scope_identity()
[java] Hibernate:
[java] update
[java] Child
[java] set
[java] parent_id=?
[java] where
[java] id=?
[java] Hibernate:
[java] update
[java] Child
[java] set
[java] parent_id=?
[java] where
[java] id=?
[java] Hibernate:
[java] update
[java] Child
[java] set
[java] parent_id=?
[java] where
[java] id=?
[java] 09:12:57,390 INFO SessionFactoryImpl:831 - closing
[java] 09:12:57,390 INFO DriverManagerConnectionProvider:147 - cleaning up
connection pool: jdbc:odbc:MySQL
BUILD SUCCESSFUL
Total time: 5 seconds
Debug level Hibernate log excerpt:
Included in the above description.That's not the right mapping for the 1:m relationship in Hibernate.
First of all, I believe the recommendation is to have a separate .hbm.xml file for each class, so you should have one for Parent and Child.
Second, you'll find the proper syntax for a one-to-many relationship here:
http://www.hibernate.org/hib_docs/v3/reference/en/html/tutorial.html#tutorial-associations
See if those help.
The tutorial docs for Hibernate are quite good. I'd recommend going through them carefully.
% -
Urgent : java bean having bidirectional one to many relationship
Hi,
We have complex requirement in our application.
We need to copy java bean having bidirectional one to many relationship to another javabean having bidirectional one to many relationship..
E.g
Class Basket1 {
public String color;
pubic String type;
public List<Basket1> basketList = new ArrayList()
Class Basket2 {
public String color;
pubic String type;
public List<Basket2> basketList = new ArrayList()
We need to exact copy Basket1 to Basket2. We are in trouble to copy List of child because we do not have how many child Basket1 have of same type..
Can someone help us how we can implement such kind of complex object bidirectional one to many relationship??I can't see anything bidirectional about these relationships. What I can see is a couple of BasketN classes that look identical so I don't know why they both exist, and they both contain lists of themselves as members, which suggests some kind of tree structure. Nothing bidirectional there. I can see tat these things can form circular object graphs but I don't see why you would want to do that.
We need to exact copy Basket1 to Basket2And I don't know what that means. Please explain. -
Hi,
I am haviing a crystal report problem. The problem relates to a one-to-many relationship involving two tables.
I have a similar setup to the following:
I have 2 database tables: table1 & table2
table1 consists of 3 fields:
{id#}, {yes/no},{up/down}
table2 consists of 2 fields:
{id#},
the field can contain any of the following values: 'open', 'closed', 'final', 'complete'.
The problem is that there exist many states to one id#.
I have a bar graph in my report that displays a bar for the count of the{yes/no} field and a bar for the count of the {up/down} field. I want also a bar for the count of when the field = 'final'.
What happens when I write a formula for the field in the second table and place it in the 'show values' section of the chart expert, is the count displayed in each bar on the graph increases significantly. I am assuming this is because there are multiple records in table 2 for each record in table 1.
What I want to happen is that the graph displays bar 1 and bar 2 correctly and then when I put in the formula for the third bar, it simply displays that bar with the count for when the field = 'final'. I dont want it to affect the whole garph.
Has anyone got any suggestions on how I can do this?
I have tried messing around with the distinct records setting in crystal and also by writing an sql query specifying DISTINCT keyword instead of using the select expert, but to no avail.
Please please can someone help me with this issue.
Thank you.
JYou can add a 1-1 query key through the code API in a descriptor amendment method. You could also define a selection criteria on the 1-m mapping to filter the type=2.
Example: (see Foundation Library manual 8-17)
OneToOneQueryKey queryKey = new OneToOneQueryKey();
queryKey.setName("organization");
queryKey.setReferenceClass(Organization.class);
ExpressionBuilder builder = new ExpressionBuilder();
queryKey.setJoinCriteria(builder.getField("ORGANIZATION.ORG_ID").equal(builder.getParameter("RELATIONSHIP.PARENT_ID").and(builder.getParamater("RELATIONSHIP.RELATIONSHIP_TYPE").equal(2)));
relationDescriptor.addQueryKey(queryKey);
Example: (of 1-m mapping with selection criteria)
OneToManyMapping mapping = new OneToManyMapping();
mapping.setReferenceClass(Relation.class);
mapping.setTargetForeignKey("RELATION.PARENT_ID");
ExpressionBuilder builder = new ExpressionBuilder();
mapping.setSelectionCriteria(builder.getField("RELATIONSHIP.PARENT_ID").equal(builder.getParameter("ORGANIZATION.ORG_ID").and(builder.getField("RELATIONSHIP.RELATIONSHIP_TYPE").equal(2)));
orgDescriptor.addMapping(mapping); -
One to Many with multiple tables on One side and one table on Many side
Sorry for the confusion in the title. Here is my question. In my program, I have 2 different tables which store 2 different type of entities. Each one of entities has a list of attachments which I stored in a common attachment table. There is a one-to-many relationship between entity tables and attachment table.
ENTITY_ONE (
ID
NAME
ENTITY_TWO (
ID
NAME
ATTACHMENTS (
ID
ENTITY_ID
ATTACHMENT_NAME
ENTITY_ID in ATTACHMENTS table is used to link attachments to either entity one or entity two. All IDs are generated by one sequence. So they are always unique. My question is how I could map this relationship into EntityOne, EntityTwo and Attachment JAVA class?For EntityOne and EntityTwo you can just define a normal OneToMany mapping using the foreign key.
Are you using JPA, or the TopLink API? JPA requires a mappedBy for the OneToMany, so this may be more difficult. You should be able to just add a JoinColumn on the OneToMany and make the column insertable/updateable=false.
For the attachment, you could either map the foreign key as a Basic (DirectToFieldMapping) and maintain it in your model, or use a VariableOneToOne mapping in TopLink (this will require the entities share a common interface).
James : http://www.eclipselink.org : http://en.wikibooks.org/wiki/Java_Persistence -
How can I pass variables from one project to another using Javascript?
Hi all, I am trying to do this: let learners take one course and finish a quiz. Then based on their quiz scores, they will be sent to other differenct courses.
However, I wish keep track on their previous quiz scores as well as many other variables.
I found this nice widge of upload/download variables by CPguru (http://www.cpguru.com/2011/05/18/save-and-load-data-widget-for-adobe-captivate-4-and-adobe -captivate-5/). However, this widget works by storing variables from one project in local computer and then upload it to another project.
My targeted learners may not always use the same computer though, so using this widget seems not work.
All these courses resided in a local-made LMS which I don't have access to their code. Therefore, passing variables to PHP html files seems not work.
Based on my limited programing knowledge, I assume that using Javascript to pass variables may be the only possible way.
Can someone instruct me how to do this?
Thank you very much.If you create two MIDlet in a midlet suite, it will display as you mentioned means you can't change the display style.
-
How do I input multiple numbers to go to multiple variables in one line?
I was wondering what I had to do to input 5 variables on one line. I have the program running fine, but I'm stuck at the part where it says "The numbers will be input five per line, on four lines".. Aside from poor grammar, it doesn't make any sense to me. Here's the whole question:
Write code that will fill the array twoDArray(declared in the line of code below) with numbers typed in at the keyboard. The numbers will be input five per line, on four lines. Use the following array declaration:I don't need any immediate help with the array itself, just the input (unless the input is directly related to the array). Just in case, I'm going to post my code. This is still very messy, because I'm not done, and it's might be somewhat sloppy as I'm new to 2d arrays (in java).
Thanks for the help.
import java.io.*;
class darrays
public static void main(String[] args) throws IOException
InputStreamReader inStream = new InputStreamReader (System.in);
BufferedReader stdin = new BufferedReader(inStream);
int[][] twoDArray = new int[4][5];
int x,y;
String input;
for (x = 0; x <= 3; x++)
for (y = 0; y<=4; y++)
input = stdin.readLine ();
twoDArray[x][y] = Integer.parseInt (input);
for (x = 0; x <= 3; x++)
for (y = 0; y<=4; y++)
System.out.print(twoDArray[x][y] + " ");
System.out.println("");
}Slightly off-topic
When I was learning Basic (good old Kemeny & Kurtz style, when Basic was simply a simplified Fortran, not Bill Gates style) you simply have to write
READ A, B, C, D, E
DATA 10, 20, 30, 40, 50
or something like
INPUT "A", A: INPUT "B", B etc.
In Java you are required to handle the mysteries of StringTokenizer...
Java 1.5 is promising to make it easier:
Scanner sc = Scanner.create(new File("myNumbers"));
while (sc.hasNextLong()) {
long aLong = sc.nextLong();
}where you get the longs (decimal formatted, separated with blanks) from a text file.
But not so easy as the good old INPUT statement.
Even C's scanf is not so easy, because has lots of subtleties
(when you finally mastered the esoteric art of using char* as strings, you are really fed up of char* strings, because they usually blow up due to buffer overflows or mere programmer errors, and start to use Java instead, even having to master the StringTokenizer and other classes.). -
Creating a single context index on a one-to-many and lookup table
Hello,
I've been successfully setting up text indexes on multiple columns on the same table (using MULTI_COLUMN_DATASTORE preferences), but now I have a situation with a one-to-many data collection table (with a FK to a lookup table), and I need to search columns across both of these tables. Sample code below, more of my chattering after the code block:
CREATE TABLE SUBMISSION
( SUBMISSION_ID NUMBER(10) NOT NULL,
SUBMISSION_NAME VARCHAR2(100) NOT NULL
CREATE TABLE ADVISOR_TYPE
( ADVISOR_TYPE_ID NUMBER(10) NOT NULL,
ADVISOR_TYPE_NAME VARCHAR2(50) NOT NULL
CREATE TABLE SUBMISSION_ADVISORS
( SUBMISSION_ADVISORS_ID NUMBER(10) NOT NULL,
SUBMISSION_ID NUMBER(10) NOT NULL,
ADVISOR_TYPE_ID NUMBER(10) NOT NULL,
FIRST_NAME VARCHAR(50) NULL,
LAST_NAME VARCHAR(50) NULL,
SUFFIX VARCHAR(20) NULL
INSERT INTO SUBMISSION (SUBMISSION_ID, SUBMISSION_NAME) VALUES (1, 'Some Research Paper');
INSERT INTO SUBMISSION (SUBMISSION_ID, SUBMISSION_NAME) VALUES (2, 'Thesis on 17th Century Weather Patterns');
INSERT INTO SUBMISSION (SUBMISSION_ID, SUBMISSION_NAME) VALUES (3, 'Statistical Analysis on Sunny Days in March');
INSERT INTO ADVISOR_TYPE (ADVISOR_TYPE_ID, ADVISOR_TYPE_NAME) VALUES (1, 'Department Chair');
INSERT INTO ADVISOR_TYPE (ADVISOR_TYPE_ID, ADVISOR_TYPE_NAME) VALUES (2, 'Department Co-Chair');
INSERT INTO ADVISOR_TYPE (ADVISOR_TYPE_ID, ADVISOR_TYPE_NAME) VALUES (3, 'Professor');
INSERT INTO ADVISOR_TYPE (ADVISOR_TYPE_ID, ADVISOR_TYPE_NAME) VALUES (4, 'Associate Professor');
INSERT INTO ADVISOR_TYPE (ADVISOR_TYPE_ID, ADVISOR_TYPE_NAME) VALUES (5, 'Scientist');
INSERT INTO SUBMISSION_ADVISORS (SUBMISSION_ADVISORS_ID, SUBMISSION_ID, ADVISOR_TYPE_ID, FIRST_NAME, LAST_NAME, SUFFIX) VALUES (1,1,2,'John', 'Doe', 'PhD');
INSERT INTO SUBMISSION_ADVISORS (SUBMISSION_ADVISORS_ID, SUBMISSION_ID, ADVISOR_TYPE_ID, FIRST_NAME, LAST_NAME, SUFFIX) VALUES (2,1,2,'Jane', 'Doe', 'PhD');
INSERT INTO SUBMISSION_ADVISORS (SUBMISSION_ADVISORS_ID, SUBMISSION_ID, ADVISOR_TYPE_ID, FIRST_NAME, LAST_NAME, SUFFIX) VALUES (3,2,3,'Johan', 'Smith', NULL);
INSERT INTO SUBMISSION_ADVISORS (SUBMISSION_ADVISORS_ID, SUBMISSION_ID, ADVISOR_TYPE_ID, FIRST_NAME, LAST_NAME, SUFFIX) VALUES (4,2,4,'Magnus', 'Jackson', 'MS');
INSERT INTO SUBMISSION_ADVISORS (SUBMISSION_ADVISORS_ID, SUBMISSION_ID, ADVISOR_TYPE_ID, FIRST_NAME, LAST_NAME, SUFFIX) VALUES (5,3,5,'Williard', 'Forsberg', 'AMS');
COMMIT;I want to be able to create a text index to lump these fields together:
SUBMISSION_ADVISORS.FIRST_NAME
SUBMISSION_ADVISORS.LAST_NAME
SUBMISSION_ADVISORS.SUFFIX
ADVISOR_TYPE.ADVISOR_TYPE_NAME
I've looked at DETAIL_DATASTORE and USER_DATASTORE, but the examples in Oracle Docs for DETAIL_DATASTORE leave me a little bit perplexed. It seems like this should be pretty straightforward.
Ideally, I'm trying to avoid creating new columns, and keeping the trigger adjustments to a minimum. But I'm open to any and all suggestions. Thanks for for your time and thoughts.
-JamieI would create a procedure that creates a virtual document with tags, which is what the multi_column_datatstore does behind the scenes. Then I would use that procedure in a user_datastore, so the result is the same for multiple tables as what a multi_column_datastore does for one table. I would also use either auto_section_group or some other type of section group, so that you can search using WITHIN as with the multi_column_datastore. Please see the demonstration below.
SCOTT@orcl_11gR2> -- tables and data that you provided:
SCOTT@orcl_11gR2> CREATE TABLE SUBMISSION
2 ( SUBMISSION_ID NUMBER(10) NOT NULL,
3 SUBMISSION_NAME VARCHAR2(100) NOT NULL
4 )
5 /
Table created.
SCOTT@orcl_11gR2> CREATE TABLE ADVISOR_TYPE
2 ( ADVISOR_TYPE_ID NUMBER(10) NOT NULL,
3 ADVISOR_TYPE_NAME VARCHAR2(50) NOT NULL
4 )
5 /
Table created.
SCOTT@orcl_11gR2> CREATE TABLE SUBMISSION_ADVISORS
2 ( SUBMISSION_ADVISORS_ID NUMBER(10) NOT NULL,
3 SUBMISSION_ID NUMBER(10) NOT NULL,
4 ADVISOR_TYPE_ID NUMBER(10) NOT NULL,
5 FIRST_NAME VARCHAR(50) NULL,
6 LAST_NAME VARCHAR(50) NULL,
7 SUFFIX VARCHAR(20) NULL
8 )
9 /
Table created.
SCOTT@orcl_11gR2> INSERT ALL
2 INTO SUBMISSION (SUBMISSION_ID, SUBMISSION_NAME)
3 VALUES (1, 'Some Research Paper')
4 INTO SUBMISSION (SUBMISSION_ID, SUBMISSION_NAME)
5 VALUES (2, 'Thesis on 17th Century Weather Patterns')
6 INTO SUBMISSION (SUBMISSION_ID, SUBMISSION_NAME)
7 VALUES (3, 'Statistical Analysis on Sunny Days in March')
8 SELECT * FROM DUAL
9 /
3 rows created.
SCOTT@orcl_11gR2> INSERT ALL
2 INTO ADVISOR_TYPE (ADVISOR_TYPE_ID, ADVISOR_TYPE_NAME)
3 VALUES (1, 'Department Chair')
4 INTO ADVISOR_TYPE (ADVISOR_TYPE_ID, ADVISOR_TYPE_NAME)
5 VALUES (2, 'Department Co-Chair')
6 INTO ADVISOR_TYPE (ADVISOR_TYPE_ID, ADVISOR_TYPE_NAME)
7 VALUES (3, 'Professor')
8 INTO ADVISOR_TYPE (ADVISOR_TYPE_ID, ADVISOR_TYPE_NAME)
9 VALUES (4, 'Associate Professor')
10 INTO ADVISOR_TYPE (ADVISOR_TYPE_ID, ADVISOR_TYPE_NAME)
11 VALUES (5, 'Scientist')
12 SELECT * FROM DUAL
13 /
5 rows created.
SCOTT@orcl_11gR2> INSERT ALL
2 INTO SUBMISSION_ADVISORS (SUBMISSION_ADVISORS_ID, SUBMISSION_ID, ADVISOR_TYPE_ID, FIRST_NAME, LAST_NAME, SUFFIX)
3 VALUES (1,1,2,'John', 'Doe', 'PhD')
4 INTO SUBMISSION_ADVISORS (SUBMISSION_ADVISORS_ID, SUBMISSION_ID, ADVISOR_TYPE_ID, FIRST_NAME, LAST_NAME, SUFFIX)
5 VALUES (2,1,2,'Jane', 'Doe', 'PhD')
6 INTO SUBMISSION_ADVISORS (SUBMISSION_ADVISORS_ID, SUBMISSION_ID, ADVISOR_TYPE_ID, FIRST_NAME, LAST_NAME, SUFFIX)
7 VALUES (3,2,3,'Johan', 'Smith', NULL)
8 INTO SUBMISSION_ADVISORS (SUBMISSION_ADVISORS_ID, SUBMISSION_ID, ADVISOR_TYPE_ID, FIRST_NAME, LAST_NAME, SUFFIX)
9 VALUES (4,2,4,'Magnus', 'Jackson', 'MS')
10 INTO SUBMISSION_ADVISORS (SUBMISSION_ADVISORS_ID, SUBMISSION_ID, ADVISOR_TYPE_ID, FIRST_NAME, LAST_NAME, SUFFIX)
11 VALUES (5,3,5,'Williard', 'Forsberg', 'AMS')
12 SELECT * FROM DUAL
13 /
5 rows created.
SCOTT@orcl_11gR2> -- constraints presumed based on your description:
SCOTT@orcl_11gR2> ALTER TABLE submission ADD CONSTRAINT submission_id_pk
2 PRIMARY KEY (submission_id)
3 /
Table altered.
SCOTT@orcl_11gR2> ALTER TABLE advisor_type ADD CONSTRAINT advisor_type_id_pk
2 PRIMARY KEY (advisor_type_id)
3 /
Table altered.
SCOTT@orcl_11gR2> ALTER TABLE submission_advisors ADD CONSTRAINT submission_advisors_id_pk
2 PRIMARY KEY (submission_advisors_id)
3 /
Table altered.
SCOTT@orcl_11gR2> ALTER TABLE submission_advisors ADD CONSTRAINT submission_id_fk
2 FOREIGN KEY (submission_id) REFERENCES submission (submission_id)
3 /
Table altered.
SCOTT@orcl_11gR2> ALTER TABLE submission_advisors ADD CONSTRAINT advisor_type_id_fk
2 FOREIGN KEY (advisor_type_id) REFERENCES advisor_type (advisor_type_id)
3 /
Table altered.
SCOTT@orcl_11gR2> -- resulting data:
SCOTT@orcl_11gR2> COLUMN submission_name FORMAT A45
SCOTT@orcl_11gR2> COLUMN advisor FORMAT A40
SCOTT@orcl_11gR2> SELECT s.submission_name,
2 a.advisor_type_name || ' ' ||
3 sa.first_name || ' ' ||
4 sa.last_name || ' ' ||
5 sa.suffix AS advisor
6 FROM submission_advisors sa,
7 submission s,
8 advisor_type a
9 WHERE sa.advisor_type_id = a.advisor_type_id
10 AND sa.submission_id = s.submission_id
11 /
SUBMISSION_NAME ADVISOR
Some Research Paper Department Co-Chair John Doe PhD
Some Research Paper Department Co-Chair Jane Doe PhD
Thesis on 17th Century Weather Patterns Professor Johan Smith
Thesis on 17th Century Weather Patterns Associate Professor Magnus Jackson MS
Statistical Analysis on Sunny Days in March Scientist Williard Forsberg AMS
5 rows selected.
SCOTT@orcl_11gR2> -- procedure to create virtual documents:
SCOTT@orcl_11gR2> CREATE OR REPLACE PROCEDURE submission_advisors_proc
2 (p_rowid IN ROWID,
3 p_clob IN OUT NOCOPY CLOB)
4 AS
5 BEGIN
6 FOR r1 IN
7 (SELECT *
8 FROM submission_advisors
9 WHERE ROWID = p_rowid)
10 LOOP
11 IF r1.first_name IS NOT NULL THEN
12 DBMS_LOB.WRITEAPPEND (p_clob, 12, '<first_name>');
13 DBMS_LOB.WRITEAPPEND (p_clob, LENGTH (r1.first_name), r1.first_name);
14 DBMS_LOB.WRITEAPPEND (p_clob, 13, '</first_name>');
15 END IF;
16 IF r1.last_name IS NOT NULL THEN
17 DBMS_LOB.WRITEAPPEND (p_clob, 11, '<last_name>');
18 DBMS_LOB.WRITEAPPEND (p_clob, LENGTH (r1.last_name), r1.last_name);
19 DBMS_LOB.WRITEAPPEND (p_clob, 12, '</last_name>');
20 END IF;
21 IF r1.suffix IS NOT NULL THEN
22 DBMS_LOB.WRITEAPPEND (p_clob, 8, '<suffix>');
23 DBMS_LOB.WRITEAPPEND (p_clob, LENGTH (r1.suffix), r1.suffix);
24 DBMS_LOB.WRITEAPPEND (p_clob, 9, '</suffix>');
25 END IF;
26 FOR r2 IN
27 (SELECT *
28 FROM submission
29 WHERE submission_id = r1.submission_id)
30 LOOP
31 DBMS_LOB.WRITEAPPEND (p_clob, 17, '<submission_name>');
32 DBMS_LOB.WRITEAPPEND (p_clob, LENGTH (r2.submission_name), r2.submission_name);
33 DBMS_LOB.WRITEAPPEND (p_clob, 18, '</submission_name>');
34 END LOOP;
35 FOR r3 IN
36 (SELECT *
37 FROM advisor_type
38 WHERE advisor_type_id = r1.advisor_type_id)
39 LOOP
40 DBMS_LOB.WRITEAPPEND (p_clob, 19, '<advisor_type_name>');
41 DBMS_LOB.WRITEAPPEND (p_clob, LENGTH (r3.advisor_type_name), r3.advisor_type_name);
42 DBMS_LOB.WRITEAPPEND (p_clob, 20, '</advisor_type_name>');
43 END LOOP;
44 END LOOP;
45 END submission_advisors_proc;
46 /
Procedure created.
SCOTT@orcl_11gR2> SHOW ERRORS
No errors.
SCOTT@orcl_11gR2> -- examples of virtual documents that procedure creates:
SCOTT@orcl_11gR2> DECLARE
2 v_clob CLOB := EMPTY_CLOB();
3 BEGIN
4 FOR r IN
5 (SELECT ROWID rid FROM submission_advisors)
6 LOOP
7 DBMS_LOB.CREATETEMPORARY (v_clob, TRUE);
8 submission_advisors_proc (r.rid, v_clob);
9 DBMS_OUTPUT.PUT_LINE (v_clob);
10 DBMS_LOB.FREETEMPORARY (v_clob);
11 END LOOP;
12 END;
13 /
<first_name>John</first_name><last_name>Doe</last_name><suffix>PhD</suffix><submission_name>Some
Research Paper</submission_name><advisor_type_name>Department Co-Chair</advisor_type_name>
<first_name>Jane</first_name><last_name>Doe</last_name><suffix>PhD</suffix><submission_name>Some
Research Paper</submission_name><advisor_type_name>Department Co-Chair</advisor_type_name>
<first_name>Johan</first_name><last_name>Smith</last_name><submission_name>Thesis on 17th Century
Weather Patterns</submission_name><advisor_type_name>Professor</advisor_type_name>
<first_name>Magnus</first_name><last_name>Jackson</last_name><suffix>MS</suffix><submission_name>The
sis on 17th Century Weather Patterns</submission_name><advisor_type_name>Associate
Professor</advisor_type_name>
<first_name>Williard</first_name><last_name>Forsberg</last_name><suffix>AMS</suffix><submission_name
Statistical Analysis on Sunny Days inMarch</submission_name><advisor_type_name>Scientist</advisor_type_name>
PL/SQL procedure successfully completed.
SCOTT@orcl_11gR2> -- user_datastore that uses procedure:
SCOTT@orcl_11gR2> BEGIN
2 CTX_DDL.CREATE_PREFERENCE ('sa_datastore', 'USER_DATASTORE');
3 CTX_DDL.SET_ATTRIBUTE ('sa_datastore', 'PROCEDURE', 'submission_advisors_proc');
4 END;
5 /
PL/SQL procedure successfully completed.
SCOTT@orcl_11gR2> -- index (on optional extra column) that uses user_datastore and section group:
SCOTT@orcl_11gR2> ALTER TABLE submission_advisors ADD (any_column VARCHAR2(1))
2 /
Table altered.
SCOTT@orcl_11gR2> CREATE INDEX submission_advisors_idx
2 ON submission_advisors (any_column)
3 INDEXTYPE IS CTXSYS.CONTEXT
4 PARAMETERS
5 ('DATASTORE sa_datastore
6 SECTION GROUP CTXSYS.AUTO_SECTION_GROUP')
7 /
Index created.
SCOTT@orcl_11gR2> -- what is tokenized, indexed, and searchable:
SCOTT@orcl_11gR2> SELECT token_text FROM dr$submission_advisors_idx$i
2 /
TOKEN_TEXT
17TH
ADVISOR_TYPE_NAME
AMS
ANALYSIS
ASSOCIATE
CENTURY
CHAIR
CO
DAYS
DEPARTMENT
DOE
FIRST_NAME
FORSBERG
JACKSON
JANE
JOHAN
JOHN
LAST_NAME
MAGNUS
MARCH
PAPER
PATTERNS
PHD
PROFESSOR
RESEARCH
SCIENTIST
SMITH
STATISTICAL
SUBMISSION_NAME
SUFFIX
SUNNY
THESIS
WEATHER
WILLIARD
34 rows selected.
SCOTT@orcl_11gR2> -- sample searches across all data:
SCOTT@orcl_11gR2> VARIABLE search_string VARCHAR2(100)
SCOTT@orcl_11gR2> EXEC :search_string := 'professor'
PL/SQL procedure successfully completed.
SCOTT@orcl_11gR2> SELECT s.submission_name,
2 a.advisor_type_name || ' ' ||
3 sa.first_name || ' ' ||
4 sa.last_name || ' ' ||
5 sa.suffix AS advisor
6 FROM submission_advisors sa,
7 submission s,
8 advisor_type a
9 WHERE CONTAINS (sa.any_column, :search_string) > 0
10 AND sa.advisor_type_id = a.advisor_type_id
11 AND sa.submission_id = s.submission_id
12 /
SUBMISSION_NAME ADVISOR
Thesis on 17th Century Weather Patterns Professor Johan Smith
Thesis on 17th Century Weather Patterns Associate Professor Magnus Jackson MS
2 rows selected.
SCOTT@orcl_11gR2> EXEC :search_string := 'doe'
PL/SQL procedure successfully completed.
SCOTT@orcl_11gR2> /
SUBMISSION_NAME ADVISOR
Some Research Paper Department Co-Chair John Doe PhD
Some Research Paper Department Co-Chair Jane Doe PhD
2 rows selected.
SCOTT@orcl_11gR2> EXEC :search_string := 'paper'
PL/SQL procedure successfully completed.
SCOTT@orcl_11gR2> /
SUBMISSION_NAME ADVISOR
Some Research Paper Department Co-Chair John Doe PhD
Some Research Paper Department Co-Chair Jane Doe PhD
2 rows selected.
SCOTT@orcl_11gR2> -- sample searches within specific columns:
SCOTT@orcl_11gR2> EXEC :search_string := 'chair'
PL/SQL procedure successfully completed.
SCOTT@orcl_11gR2> SELECT s.submission_name,
2 a.advisor_type_name || ' ' ||
3 sa.first_name || ' ' ||
4 sa.last_name || ' ' ||
5 sa.suffix AS advisor
6 FROM submission_advisors sa,
7 submission s,
8 advisor_type a
9 WHERE CONTAINS (sa.any_column, :search_string || ' WITHIN advisor_type_name') > 0
10 AND sa.advisor_type_id = a.advisor_type_id
11 AND sa.submission_id = s.submission_id
12 /
SUBMISSION_NAME ADVISOR
Some Research Paper Department Co-Chair John Doe PhD
Some Research Paper Department Co-Chair Jane Doe PhD
2 rows selected.
SCOTT@orcl_11gR2> EXEC :search_string := 'phd'
PL/SQL procedure successfully completed.
SCOTT@orcl_11gR2> SELECT s.submission_name,
2 a.advisor_type_name || ' ' ||
3 sa.first_name || ' ' ||
4 sa.last_name || ' ' ||
5 sa.suffix AS advisor
6 FROM submission_advisors sa,
7 submission s,
8 advisor_type a
9 WHERE CONTAINS (sa.any_column, :search_string || ' WITHIN suffix') > 0
10 AND sa.advisor_type_id = a.advisor_type_id
11 AND sa.submission_id = s.submission_id
12 /
SUBMISSION_NAME ADVISOR
Some Research Paper Department Co-Chair John Doe PhD
Some Research Paper Department Co-Chair Jane Doe PhD
2 rows selected.
SCOTT@orcl_11gR2> EXEC :search_string := 'weather'
PL/SQL procedure successfully completed.
SCOTT@orcl_11gR2> SELECT s.submission_name,
2 a.advisor_type_name || ' ' ||
3 sa.first_name || ' ' ||
4 sa.last_name || ' ' ||
5 sa.suffix AS advisor
6 FROM submission_advisors sa,
7 submission s,
8 advisor_type a
9 WHERE CONTAINS (sa.any_column, :search_string || ' WITHIN submission_name') > 0
10 AND sa.advisor_type_id = a.advisor_type_id
11 AND sa.submission_id = s.submission_id
12 /
SUBMISSION_NAME ADVISOR
Thesis on 17th Century Weather Patterns Professor Johan Smith
Thesis on 17th Century Weather Patterns Associate Professor Magnus Jackson MS
2 rows selected.
Maybe you are looking for
-
Downloading a video in an enterprise across ipads
We have issued ipads to all all sales people and would like to distribute content like marketing videos etc, through services like yousendit or dropbox without having to go through itunes. What is the best way to do that. Right now, we have doing a w
-
I need a phone number to ring for help
I been a phone number to ring for help to got started with my new iPad thanks
-
Solaris 11.1 Comstar FC target
Hello, I have a problem with the comstar as a FC target. New install of Solaris 11.1 HBA is an Emulex LPe11002 Brocade 5100B switches 2x 10x 3TB NL-SAS disks in raidz2 in pool It all works, but the speed is unusable slow to the LUN. iSCSI work and I
-
Itunes Store will not open with firefox, why?
I have recently started using firefox as my browser. However when i try and open itunes store through my itunes on the desktop, an error tells me the network cannot be recognised. Can you help me with this please?
-
Cannot open raw files on CS4 extended even with plug in
Cannot open raw files from canon eos 400d in photoshop Cs4 extended. I have updated camera raw plug in and DNG converter but still no luck! I cannot get the images off the camera onto a file. Help, images of my 5 month old daughter are on the camera