Cannot set UDTs in a jooq insert, consistently getting a StackOverflowError - postgresql

The SQL is pretty simple:
CREATE TYPE audit_fields AS (
creation_time_ms BIGINT
);
CREATE TABLE users(
...
audit AUDIT_FIELDS NOT NULL
);
These are two ways I have tried to do this:
UsersRecord getRecord() {
return new UsersRecord()
.setSomeField(...)
.setOtherField(...)
.setAudit(new AuditFieldsRecord(System.currentTimeMillis()));
}
create.insertInto(Tables.USERS)
.set(getRecord())
.execute();
And, this:
create.insertInto(Tables.USERS)
.set(getRecord())
.set(Tables.USERS.AUDIT, new AuditFieldsRecord(System.currentTimemillis()))
.execute();
I am simply getting a StackOverflowError, with the following block repeating throughout (obviously an infinite-recursion):
at org.jooq.impl.UDTConstant.<init>(UDTConstant.java:62)
at org.jooq.impl.DSL.val(DSL.java:12781)
at org.jooq.impl.DSL.val(DSL.java:12732)
at org.jooq.impl.DSL.inline(DSL.java:12590)
at org.jooq.impl.UDTRecordImpl.toString(UDTRecordImpl.java:141)
at java.lang.String.valueOf(String.java:2994)
at org.jooq.impl.AbstractParam.name(AbstractParam.java:104)
at org.jooq.impl.AbstractParam.<init>(AbstractParam.java:78)
at org.jooq.impl.AbstractParam.<init>(AbstractParam.java:74)
at org.jooq.impl.UDTConstant.<init>(UDTConstant.java:62)
at org.jooq.impl.DSL.val(DSL.java:12781)
at org.jooq.impl.DSL.val(DSL.java:12732)
at org.jooq.impl.DSL.inline(DSL.java:12590)
at org.jooq.impl.UDTRecordImpl.toString(UDTRecordImpl.java:141)
at java.lang.String.valueOf(String.java:2994)
at org.jooq.impl.AbstractParam.name(AbstractParam.java:104)
at org.jooq.impl.AbstractParam.<init>(AbstractParam.java:78)
at org.jooq.impl.AbstractParam.<init>(AbstractParam.java:74)
at org.jooq.impl.UDTConstant.<init>(UDTConstant.java:62)
at org.jooq.impl.DSL.val(DSL.java:12781)
at org.jooq.impl.DSL.val(DSL.java:12732)
at org.jooq.impl.DSL.inline(DSL.java:12590)
at org.jooq.impl.UDTRecordImpl.toString(UDTRecordImpl.java:141)
at java.lang.String.valueOf(String.java:2994)
at org.jooq.impl.AbstractParam.name(AbstractParam.java:104)
at org.jooq.impl.AbstractParam.<init>(AbstractParam.java:78)
at org.jooq.impl.AbstractParam.<init>(AbstractParam.java:74)
at org.jooq.impl.UDTConstant.<init>(UDTConstant.java:62)
Any idea what I am doing wrong?

This is an issue that exists in older versions of Jooq 3.7.0. For projects who are using that version and cannot migrate easily to newer versions, this question might be a starting point, so I am not voting to close it (other's are requested to if they see fit).
Upgrading to a later version of jooq fixes this issue.

Related

CRM D365 update polymorphic/multitable lookup via Plugin

I'm trying to update a polymorphic lookup column on a table via plugin code and it doesn't seem happening. Wondering what additional I’m missing.
var entity1Id = "af435c64-a264-4f2a-9cee-22069ce36b3c";
var destinationEntity = new Entity("bookableresourcebooking", new Guid(myBookingGuid));
destinationEntity["my_ploymorphiclookupid"] = new EntityReference("my_entity1", new Guid(entity1Id));
organizationService.Update(destinationEntity);
my_ploymorphiclookupid is a polymorphic lookup (N:1) to my_entity1
Code looks fine. If you didn’t see any runtime errors in plug-in trace log, then few diagnosis steps needed.
Check audit history of that record
Chances of any other plugin steps replacing the value back or rolling back
Try to profile/debug the plugin for clues

MongoDB unique index allows duplication

I am new in mongoDb and I have a problem with mongock. Previously I had an index defined by annotation like below. In my unit test I have a case which tries to save same value on the same field and it throws exception as expected.
#Indexed(unique = true)
private String name;
I removed #Indexed annotation and I created index by mongock migration. But in this time I am able to insert a record with same value for this column without getting exception. So what is wrong here and why it is not working as it works above. I created my migration as :
collection.createIndex(
new Document(new ImmutableMap.Builder<String, Object>()
.put("name", 1)
.build()),
new IndexOptions().name("name_idx").unique(true),
);
Without providing information about the version you are using, it's hard to say.
However I believe your issue can be related to an old existing bug.
Please use the last version 4.0.8.alpha, which is alpha as features are still being added, but very stable(there is no official documentation yet, but you can see the sample project here) or the last official stable version: 3.3.2.
Please notice that in both case you should use MongockTemplate, instead of MongoTemplate.
I believe that will solve your issue. Otherwise, please provide version and stack trace.

Npgsql support for getting jsonb field as stream

I am trying to do the following on a jsonb field:
using (var reader = cmd.ExecuteReader())
{
while (reader.Read())
{
using (var results = reader.GetStream(0))
{
results.CopyTo(stream);
}
}
reader.Close();
}
and getting an exception telling me that GetStream is not supported for this field.
Am I missing something here or is it Npgsql that simply doesn't support streaming jsonb fields (yet)?
This is already handled in the next version of Npgsql, 3.1. Unfortunately that version is still in alpha, hopefully I'll be able to release a beta in around two months.
In the meantime you can work around this by reading the jsonb as a string, and if needed, wrapping a TextReader around it (may not be as efficient but will work).

what could I be missing in my typo3 extension to cause a table does not exist error?

I am getting this error after adding to an extension a class from another extension:
Uncaught TYPO3 Exception
#1247602160: Table 'deva.tx_bingoprizes_domain_model_hall' doesn't exist: SELECT tx_bingoprizes_domain_model_hall.* FROM tx_bingoprizes_domain_model_hall WHERE tx_bingoprizes_domain_model_hall.uid IN ('0') LIMIT 1
Tx_Extbase_Persistence_Storage_Exception_SqlError thrown in file
/home/typo3_src/typo3_src-4.5.32/typo3/sysext/extbase/Classes/Persistence/Storage/Typo3DbBackend.php in line 1008.
The class added is tx_bingoprizes_domain_model_hall which should be reading from the table tx_bpscore_domain_model_hall as I added to the setup file:
config.tx_extbase.persistence.classes {
Tx_Bingoprizes_Domain_Model_Hall {
mapping {
tableName = tx_bpscore_domain_model_hall
}
}
}
as I did for other extension which also reuses this class and which works properly ( I use it as my model for how to do this and as near as I can tell did everything the same way ). Why is typo3 still trying to use table tx_bingoprizes_domain_model_hall? where else do I need to specify the other table? I tried restarting the server, clearing caches, reinstalling the extension but still get the error.
I am using the latest 4.5 typo3.
Thanks
to reiterate my comment as the answer...
OK, I got it. Once again I had forgotten to INCLUDE the necessary item (in this case bingoprizes) to the page's template. So the error was not in my extension but in the typo3 config for the page. I hate that, forget it all the time, it is counter-intuitive to me as I find it natural to assume the setup.txt stuff is auto included on any page that uses my extension.

Data models generated by Sqlautocode: 'RelationshipProperty' object has no attribute 'c'

Using PGModeler, we created a schema and then exported out some appropriate SQL code. The SQL commands were able to populate the appropriate tables and rows in our Postgres database.
From here, we wanted to create declarative Sqlalchemy models, and so went with Sqlautocode. We ran it at the terminal:
sqlautocode postgresql+psycopg2://username:password#host/db_name -o models.py -d
And it generated our tables and corresponding models as expected. So far, zero errors.
Then, when going to ipython, I imported everything from models.py and simply tried creating an instance of a class defined there. Suddenly, I get this error:
AttributeError: 'RelationshipProperty' object has no attribute 'c'
This one left me confused for a while. The other SO threads that discuss this had solutions nowhere near my issue (often related to a specific framework or syntax not being used by sqlautocode).
After finding the reason, I decided to document the issue at hand. See below.
Our problem was simply due to bad naming given to our variables when sqlautocode ran. Specifically, the bad naming happened with any model that had a foreign key to itself.
Here's an example:
#Note that all \"relationship\"s below are now \"relation\"
#it is labeled relationship here because I was playing around...
service_catalog = Table(u'service_catalog', metadata,
Column(u'id', BIGINT(), nullable=False),
Column(u'uuid', UUID(), primary_key=True, nullable=False),
Column(u'organization_id', INTEGER(), ForeignKey('organization.id')),
Column(u'type', TEXT()),
Column(u'name', TEXT()),
Column(u'parent_service_id', BIGINT(), ForeignKey('service_catalog.id')),
)
#Later on...
class ServiceCatalog(DeclarativeBase):
__table__ = service_catalog
#relation definitions
organization = relationship('Organization', primaryjoin='ServiceCatalog.organization_id==Organization.id')
activities = relationship('Activity', primaryjoin='ServiceCatalog.id==ActivityService.service_id', secondary=activity_service, secondaryjoin='ActivityService.activity_id==Activity.id')
service_catalog = relationship('ServiceCatalog', primaryjoin='ServiceCatalog.parent_service_id==ServiceCatalog.id')
organizations = relationship('Organization', primaryjoin='ServiceCatalog.id==ServiceCatalog.parent_service_id', secondary=service_catalog, secondaryjoin='ServiceCatalog.organization_id==Organization.id')
In ServiceCatalog.organizations, it is looking to have the secondary table be service_catalog, but that variable was just overwritten locally. Switching the order of the two will fix this issue.