Propel ORM: Query searches for table name in starting character in uppercase - propel2

I am using Propel ORM
<table name="tawcompanyresearch" idMethod="native" phpName="Tawcompanyresearch">
<column name="TawCompanyResearchID" phpName="Tawcompanyresearchid" type="INTEGER" primaryKey="true" autoIncrement="true" required="true"/>
This is the generator in my schema.xml. When I make a query it returns as
42S02 - SQLSTATE[42S02]: Base table or view not found: 1146 Table 'taw.Tawcompanyresearch' doesn't exist
Please note that the table name is in small letters but search result returns the first character of the table as capital.
Where can this value be changed? Please give me some insights of this error.
Thank You

Related

Nifi throwing None of the fields in the record map to the columns defined by [table name]

Am trying execute a sql query on oracle database and inserting the result into another table, for my trial am just performing a simple query as
SELECT 1 AS count
FROM dual
and trying to insert that into a single column table which has the name COUNT.
The content of the record on Nifi seems to be as follows
[
{
"COUNT" : "1"
}
]
but the logs keeps throwing the error
due to java.sql.SQLDataException:
None of the fields in the record map to the columns defined by
the schema_name.table_name table:
any ideas ?
I believe you get that same error message if your table name doesn't match. The Translate Field Names property only translates the fields (columns), not the table name. Try specifying the schema/table in uppercase to match what Oracle is expecting.

Laravel / Eloquent -- Lookup Table Issue

I have 3 tables that I am trying to work through and am having a hard time connecting them via Eloquent joins.
Character Table
profileID (PK)
Character Gear Table
profileId (PK)
qualityId (FK)
Quality Lookup Table
id (PK)
name
I am able to access the Character Gear Lookup with the following in my Character Model:
public function gear()
{
return $this->hasMany('App\Models\CharacterGear', 'profileId')->where('gearSet', '=', '0');
}
How do I get the lookup to work so that I can get the quality name from the Quality Lookup table to tie in to the gear() shown above?
Please let me know if you need any further information!
Figured it out. Eloquent has Nested Relationships and I didn't know that.

Preconditions column exists

Using liquibase 3.4.1 I want to rename my columns in Oracle to uppercase if they exist.
I always get the following error no matter what I do:
Unexpected error running Liquibase: ORA-00957: duplicate column name
[Failed SQL: ALTER TABLE "SYSTEM"."MYTABLE" RENAME COLUMN "id" TO "ID"]
My precondition looks like this:
<changeSet author="sake" id="gfdgfd" dbms="oracle" objectQuotingStrategy="QUOTE_ALL_OBJECTS">
<preConditions onFail="MARK_RAN" >
<columnExists tableName="MYTABLE" columnName="id" />
</preConditions>
<renameColumn tableName="MYTABLE" oldColumnName="id" newColumnName="ID"/>
</changeSet>
I tried following:
- removing objectQuotingStrategy
- adding SQL check:
<sqlCheck expectedResult="1">
SELECT COUNT(*) FROM USER_TAB_COLUMNS
WHERE TABLE_NAME='MYTABLE'
AND COLUMN_NAME='id'
</sqlCheck>
Any idea why this happens? :/

Cannot retrieve the id of the last inserted row in Hibernate using Oracle

I'm using Hibernate Tools 3.2.1.GA with the Spring version 3.0.2. I'm trying to retrieve the id of the last inserted row into the Oracle(10g) database as follows.
Session session=NewHibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
Country c=new Country();
c.setCountryId(new BigDecimal(0));
c.setCountryName(request.getParameter("txtCountryName"));
c.setCountryCode(request.getParameter("txtCountryCode"));
Zone z=(Zone) session.get(Zone.class, new BigDecimal(request.getParameter("zoneId")));
c.setZone(z);
session.save(c);
session.flush();
System.out.println(c.getCountryId());
session.getTransaction().commit();
This statement System.out.println(c.getCountryId()); is expected to return the currently inserted id after the data is serialized to the database and before the transaction is committed but it doesn't because of the following line in the preceding code snippet (as it presumably appears to me).
c.setCountryId(new BigDecimal(0));
I'm not sure why this statement is required in my case (while inserting). I saw this statement nowhere. Omission of this line causes the following exception to be thrown.
org.hibernate.id.IdentifierGenerationException: ids for this class
must be manually assigned before calling save(): model.Country
Is this statement c.setCountryId(new BigDecimal(0)); really required during insertion? It's a sequence generated primary key in the Oracle database and because of that line, this statement System.out.println(c.getCountryId()); always returns 0 which is actually expected to return the currently inserted id in the current session.
So, how can I get the last generated id in this case? Am I following a wrong way, is there a different way?
EDIT:
CREATE TABLE "COUNTRY"
(
"COUNTRY_ID" NUMBER(35,0) NOT NULL ENABLE,
"COUNTRY_CODE" VARCHAR2(10),
"COUNTRY_NAME" VARCHAR2(50),
"ZONE_ID" NUMBER(35,0),
CONSTRAINT "COUNTRY_PK" PRIMARY KEY ("COUNTRY_ID") ENABLE,
CONSTRAINT "COUNTRY_FK" FOREIGN KEY ("ZONE_ID")
REFERENCES "ZONE" ("ZONE_ID") ON DELETE CASCADE ENABLE
)
/
CREATE OR REPLACE TRIGGER "BI_COUNTRY"
before insert on "COUNTRY"
for each row
begin
select "COUNTRY_SEQ".nextval into :NEW.COUNTRY_ID from dual;
end;
/
ALTER TRIGGER "BI_COUNTRY" ENABLE
/
The exception 'ids for this class must be manually assigned before calling save()' means that you are using the identifier generation strategy of 'Assigned'.
assigned
lets the application assign an identifier to the object before save() is called. This is the default strategy if no element is specified.
If you do not define any strategy, hibernate defaults to 'assigned'. 'assigned' strategy implies that hibernate expects that the application supplies it's own ids.
If you want to use a sequence id generator in Oracle, you can do so with the following configuration -
If you are using xml -
<id name="countryId" type="java.lang.Integer">
<column name="Country_Id" />
<generator class="sequence">
<param name="sequence">Country_Id_Seq</param>
</generator>
</id>
If you are using annotations -
#Id
#GeneratedValue(strategy=GenerationType.SEQUENCE, generator="Country_Id_Seq")
#SequenceGenerator(name="Country_Id_Seq", sequenceName="Country_Id_Seq" )
private Integer sequence;
And your code should look like so -
Country c=new Country();
c.setCountryName(request.getParameter("txtCountryName"));
c.setCountryCode(request.getParameter("txtCountryCode"));
Zone z=(Zone) session.get(Zone.class, new BigDecimal(request.getParameter("zoneId")));
c.setZone(z);
session.save(c);
session.flush();
System.out.println(c.getCountryId());
When 'session.save(c)' executes, hibernate makes the following sql call to Oracle, retrieves the id and sets it in Country object.
select Country_Id_Seq.nextVal from dual;
Problem with trigger
Since you are using a trigger to increment the id when a row is inserted, this will cause a problem with hibernate sequence. Hibernate is using the sequence to generate an id and the database is using the trigger to increment the id. This is resulting in the id being incremented twice.
You have a three options to resolve this.
Delete the trigger because it's not necessary.
If you still need the trigger because the table could be updated outside the application, you could update the trigger such that the id is generated only if the id is not set in the insert statement
HIbernate issue with Oracle Trigger for generating id from a sequence
Create a custom id generator that uses the trigger to set the id in the data before it is saved to db. Check out the following link - https://forum.hibernate.org/viewtopic.php?t=973262
If the values into an ID column generated by a sequence, then you should associate that sequence with your ID column in the entity definition so that the attribute is filled in with the ID value by Hibernate during insertion.
Using annotations:
#Id
#GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "CountryIdSequence")
#SequenceGenerator(name = "CountryIdSequence", sequenceName = "COUNTRY_ID_SEQUENCE")
#Column(name = "COUNTRY_ID")
private BigDecimal countryId;
Using hbm:
<id name="countryId" type="big_decimal">
<column name="COUNTRY_ID" />
<generator class=""sequence">
<param name="sequence">COUNTRY_ID_SEQUENCE</param>
</generator>
</id>
Then, it will be available after the save.
Any changes made to the entity at the database layer are not reflected in the hibernate entity layer until you refresh the object.
session.save(c);
session.flush();
// Refresh the object for columns modified in the DB by IDENTITY / SEQUENCE / Triggers.
session.refresh(c);
System.out.println(c.getCountryId());

query very slow longtext field innodb table

Well, firts of all, sorry by my english. I try to do a query in a table that the users can include some text, like a blog page. The users can design the content in a html format. In my table it is stored like this:
Estad&iacute;sticas<br />
<table border="0">
<tbody>
<tr>
<td>Columna 1</td>
<td>Columna 2</td>
</tr>
<tr>
<td>Columna 3<br /></td>
<td>Columna 4<br /></td>
</tr>
</tbody>
</table>
I must serch in that content all that user's want. The field 'texto' (that I'm using for it) is a longtext field and the table is innodb. I can't use full text search, 'cause it is only for myisam tables. I made the query as:
"SELECT * FROM texto WHERE texto like '%$variable%'"
but the query is very, very slow, an it take an eternity. The table has a 849 records, that's isn't big. If I write the same query in a phpmyadmin also take a very, very long time. But there are big records in this field, some records have the video html, tables, images, but it's just that, text like the above.
What I can do??? How can improve the performance of the query??? I appreciate all your help. Thanks a lot. And again, sorry for my english.
Unfortunately you can't get more from the structure you have - any clustered or non-clustered index won't be able to handle like '%...' query. The best solution would be probably to export your data to some full-text search engine (eg. SOLR) and use this engine to fulfill users queries. If it's not possible than another solution would be to create a tokens table that will play a role of a text index:
create table tokens(
token varchar(100) not null,
docid int not null references testdo(id),
constraint PK_tokens primary key (token, docid)
);
where docid references your data table (I named it testdo).
Then you need to fill the tokens table by splitting users blog posts by some common html expressions, eg.:
insert ignore into tokens values
('Estad', 1),
('Columna 1', 1),
('Columna 2', 1),
('Estad', 1);
Notice ignore keyword which will silently ignore any duplicates that may come. With tokens table filled with data you may modify your query to something like:
select * from testdo d
inner join tokens t on t.docid = d.id where t.token like 'Col%'
which should execute much faster as it's using indexes and key-lookups.
PS. You may improve the tokens table by adding a count column which will keep a number of occurrences of a given word in a document. You may then order the results by this column and make the them even more relevant to the search term.

Resources